Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 48353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:16:00+00:00 2026-05-10T16:16:00+00:00

I have a class to parse a matrix that keeps the result in an

  • 0

I have a class to parse a matrix that keeps the result in an array member:

class Parser {   ...   double matrix_[4][4]; }; 

The user of this class needs to call an API function (as in, a function I have no control over, so I can’t just change its interface to make things work more easily) that looks like this:

void api_func(const double matrix[4][4]); 

The only way I have come up with for the caller to pass the array result to the function is by making the member public:

void myfunc() {   Parser parser;   ...   api_func(parser.matrix_); } 

Is this the only way to do things? I’m astounded by how inflexible multidimensional arrays declared like this are. I thought matrix_ would essentially be the same as a double** and I could cast (safely) between the two. As it turns out, I can’t even find an unsafe way to cast between the things. Say I add an accessor to the Parser class:

void* Parser::getMatrix() {   return (void*)matrix_; } 

This will compile, but I can’t use it, because there doesn’t seem to be a way to cast back to the weirdo array type:

  // A smorgasbord of syntax errors...   api_func((double[][])parser.getMatrix());   api_func((double[4][4])parser.getMatrix());   api_func((double**)parser.getMatrix()); // cast works but it's to the wrong type 

The error is:

error C2440: ‘type cast’ : cannot convert from ‘void *’ to ‘const double [4][4]’

…with an intriguing addendum:

There are no conversions to array types, although there are conversions to references or pointers to arrays

I can’t determine how to cast to a reference or pointer to array either, albeit that it probably won’t help me here.

To be sure, at this point the matter is purely academic, as the void* casts are hardly cleaner than a single class member left public!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:16:01+00:00Added an answer on May 10, 2026 at 4:16 pm

    Here’s a nice, clean way:

    class Parser { public:    typedef double matrix[4][4];     // ...     const matrix& getMatrix() const    {       return matrix_;    }     // ...  private:   matrix matrix_; }; 

    Now you’re working with a descriptive type name rather than an array, but since it’s a typedef the compiler will still allow passing it to the unchangeable API function that takes the base type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Normally you would subclass MyClass to modify the behavior (polymorphism)… May 11, 2026 at 8:39 am
  • added an answer The correct way to do things is to leave Apache… May 11, 2026 at 8:39 am
  • added an answer When no domain is explicitly set by the server on… May 11, 2026 at 8:39 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.

      Related Questions

      No related questions found