PDA

View Full Version : struct problem...



hiuao
5th April 2007, 05:52
I just want to try to use struct for my further usage.
In the header file I define a struct:
struct refer{
double Are;
double Ere;
};

class newstruct{
public:
newstruct();
struct refer refer1;
struct refer1 a(double b,double c);
};
In the .cpp file:
struct refer1 newstruct::a(double b,double c){
refer1.Are=b;

refer1.Ere=c;
cout<<refer1.Aref<<endl
<<refer1.Eref<<endl;

return(refer1);
}
the error:
NewStruct.cpp: In member function `refer1 newstruct::a(double, double)':
NewStruct.cpp:7: error: return type `struct refer1' is incomplete
NewStruct.cpp:12: error: conversion from `refer' to non-scalar type `refer1' requested
Can anyone tell me the problem?Thank you very much!
Best Regards!

aamer4yu
5th April 2007, 06:11
U should have posteed this in General programming... nothing specific to Qt...

neways this should help u...




struct refer{
double Are;
double Ere;
};

class newstruct{
public:
newstruct();
struct refer refer1;
struct refer a(double b,double c);
};
In the .cpp file:
refer newstruct::a(double b,double c)
{
refer1.Are=b;

refer1.Ere=c;
cout<<refer1.Aref<<endl
<<refer1.Eref<<endl;

return(refer1);
}

newstruct objNewstruct;
refer r2 = objNewstruct.a(3,4);




hope this helps...

hiuao
5th April 2007, 06:16
U should have posteed this in General programming... nothing specific to Qt...

neways this should help u...




struct refer{
double Are;
double Ere;
};

class newstruct{
public:
newstruct();
struct refer refer1;
struct refer a(double b,double c);
};
In the .cpp file:
refer newstruct::a(double b,double c)
{
refer1.Are=b;

refer1.Ere=c;
cout<<refer1.Aref<<endl
<<refer1.Eref<<endl;

return(refer1);
}

newstruct objNewstruct;
refer r2 = objNewstruct.a(3,4);




hope this helps...

I just change the defination of struct a,just as you said.Then its ok!
Thank you very much!

aamer4yu
5th April 2007, 07:48
struct a ???
i guess a is a member function of the class newstruct.
The mistake u were making is that u were trying to return refer1... in return u mention return types,,,, not return data.