c++ declaring parallel arrays as functions

i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function?

pointtwod.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class PointTwoD
{
    private:
        int xcord,ycord;
        float civIndex;
        LocationData locationdata;

    public:
            PointTwoD();

            PointTwoD(int, int, string, int, int, float, float, float);

        //set/mutator function
        void setxcord(int);
        void setycord(int);

        //get/accessor function
        int getxcord();
        int getycord();

        void storedata(int, int, float);

};


PointTwoDImp.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//declaring array
void PointTwoD::storedata(int xord[], int yord[], float civ[])
{
    int i=0;
    //int size = sizeof(xord)/sizeof(xord[0]);
    int size = 100;
    for(i=0;i<100;i++)
    {
        cout << "key in num for xord: " << endl;
        xord[i] = xcord;
        cout << "key in value for yord: " << endl;
        xord[i] = ycord;
        cout << "key in value for civ: " << endl;
        civ[i] = locationdata.getCivIndex();
    };
}
int main()
{
    PointTwoD pointtwod;
    pointtwod.storedata(xord[], yord[], civ[]);
}


when i compile the error message i get was even when i i put in int xord[]; in my PointTwoD.h file:

1
2
3
4
5
6
7
8
9
10
PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'

PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)

PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token 

PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'

PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)


The error message says it all. In the prototype, you specify (int, int, float) as parameters, in the definition, you specify (int[], int[], float[]). They should match.

PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token


xord, yord, civ are not declared in the scope of main.
And even if they were, you should omit the [] suffix when passing them as parameters.
Topic archived. No new replies allowed.