To return an array from a class member function

Asked 2 years ago, Updated 2 years ago, 90 views

Create a class and there is a member function in it.

This member function must return 'array'.

By example code

class class_df {
public :
    class_df();
    void initialize();
    float class_df::calculate(int, float, float, float);
    ~class_df();
private:
    float a;
    float b;
    float c;
};
class_df::class_df() {
    initialize();
}
void initialize() {
    a = 0;
    b = 0;
    c = 0;
}

float class_df::calculate(int size, float x__, foat y__, float z__) {
    float *return_parm = {0};
    return_parm[0] = a*x__;
    return_parm[1] = a*y__;
    return_parm[2] = a*z__;

    return *return_parm;
}

class_df::~class_df() {
}

I did this, but this pops up;;;;

c++ c++11

2022-09-22 12:20

1 Answers

I think there are at least 3 grammatical errors. Try changing the code as follows.

class class_df {
    public :
    class_df();
    void initialize();
    float calculate (int, float, float); // change here.
    ~class_df();
private:
    float a;
    float b;
    float c;
};

class_df::class_df() {  
    initialize();
}
void class_df::initialize() { // changed here. The class must be specified.
    a = 0;
    b = 0;
    c = 0;
}

float class_df::calculate (int size, float x__, floaty__, float z_) { // changed here. There was a typo.
    float *return_parm = {0};
    return_parm[0] = a*x__;
    return_parm[1] = a*y__;
    return_parm[2] = a*z__;

    return *return_parm;
}

class_df::~class_df() {
}


2022-09-22 12:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.