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 1101461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:02:22+00:00 2026-05-17T01:02:22+00:00

I need to return 3 values. X, Y, Z. I’ve tried something like this,

  • 0

I need to return 3 values. X, Y, Z.
I’ve tried something like this, but it does not work, can anyone help me a bit? I’ve looked here: Return a float array in C++ and I tried to do same thing, except with 1 dimensional array to return.

class Calculate
{
 float myArray[3][4], originalArray[3][4], tempNumbers[4];
 float result[3]; // Only works when result is 2 dimensional array, but I need 1 dimension.

public:
 Calculate(float x1, float y1, float z1, float r1,
  float x2, float y2, float z2, float r2,
  float x3, float y3, float z3, float r3)
 {
  myArray[0][0] = x1;
  myArray[0][1] = y1;
  myArray[0][2] = z1;
  myArray[0][3] = r1;

  myArray[1][0] = x2;
  myArray[1][1] = y2;
  myArray[1][2] = z2;
  myArray[1][3] = r2;

  myArray[2][0] = x3;
  myArray[2][1] = y3;
  myArray[2][2] = z3;
  myArray[2][3] = r3;

  result[0] = 1;
  result[1] = 2;
  result[2] = 3;
 }

 float* operator[](int i)
 {
  return result[i]; //Value type does not match the function type
 }

 const float* operator[](int i) const
 {
  return result[i]; //Value type does not match the function type
 }
};
  • 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. Editorial Team
    Editorial Team
    2026-05-17T01:02:23+00:00Added an answer on May 17, 2026 at 1:02 am

    Instead of returning a pointer, it’s usually better practice to accept a pointer and write out the results there. That way someone can allocate a regular array on the stack and have it initialized by your Calculate.

    Something like:

    class Calculate
    {
     float myArray[3][4], originalArray[3][4], tempNumbers[4];
    
    public:
     Calculate(float x1, float y1, float z1, float r1,
      float x2, float y2, float z2, float r2,
      float x3, float y3, float z3, float r3, float *result)
     {
      myArray[0][0] = x1;
      myArray[0][1] = y1;
      myArray[0][2] = z1;
      myArray[0][3] = r1;
    
      myArray[1][0] = x2;
      myArray[1][1] = y2;
      myArray[1][2] = z2;
      myArray[1][3] = r2;
    
      myArray[2][0] = x3;
      myArray[2][1] = y3;
      myArray[2][2] = z3;
      myArray[2][3] = r3;
    
      result[0] = 1;
      result[1] = 2;
      result[2] = 3;
     }
    };
    

    Some other tweaks you can do – separate the constructor from the calculation, since constructors are more for initialization; and pass arrays for safer memory control:

    class Calculate
    {
        float myArray[3][4], originalArray[3][4], tempNumbers[4];
    
    public:
        Calculate(const float initArray[3][4])
        {
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 4; j++)
                    myArray[i][j] = initArray[i][j];
        }
    
        void DoCalculation(float result[3]) const
        {
            result[0] = 1;
            result[1] = 2;
            result[2] = 3;
        }
    };
    
    int main()
    {
        float myArray[3][4] =
        {
            { 0, 1, 2, 3 },
            { 4, 5, 6, 7 },
            { 8, 9, 0, 1 }
        };
        float result[3];
        Calculate calc(myArray);
        calc.DoCalculation(result);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually do something like the example below when I need to return error
$('input[type=checkbox]').unbind().click(function(e){ $(this).attr('checked', true) return false; }); I NEED to return false because I have
I need a function to return a suffix for days when displaying text like
For a current project I am working I need to return an aggregate report
I have a bit of PHP code which I need to return an even
in delphi7 i have a function that i need to return a array as
Working with the following code, I need to return only records where the `point'
Here is my scenario. For the example lets say that I need to return
I need a method to return a random string in the format: Letter Number
I need to know how to return a default row if no rows exist

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.