struct in class (error c2556)

clas A {
struct st
{
int a,b;
}
protected:
vector<st> f(int d, intc, int g);

}

vector<st> A:: f(int d, intc, int g)
{
st s;
for(int i=0;i<d;i++)
{
s.a=c+i;
s.b=g-i;

}
return s;
}

Dear All,
First I declare my function within the class and then I define it out of class, srill I receive error c2556 saying that f is overloaded and that have different return type which in both cases is st.
Where is the mistake
Thank you in advance!!
[620 byte] By [lontana] at [2007-11-20 11:44:37]
# 1 Re: struct in class (error c2556)
You declared the method f to return the vector<st>.
But your method f returns the object of the struct st type!
Either change the declaration to best f(int d, int c, int g);or change the object to be returned in the f implementation.
VictorN at 2007-11-10 22:22:37 >
# 2 Re: struct in class (error c2556)
clas A {
struct st
{
int a,b;
}
protected:
vector<st> f(int d, intc, int g);

}

vector<st> A:: f(int d, intc, int g)
{
st s;
vector<st> v;
for(int i=0;i<d;i++)
{
s.a=c+i;
s.b=g-i;
v.push_back(s);
}
return v;
}

I made changes still I receive the same error!!!
Thanks
lontana at 2007-11-10 22:23:42 >
# 3 Re: struct in class (error c2556)
Please, post your actual code! The code snippet you referred to cannot be compiled/tested!
VictorN at 2007-11-10 22:24:39 >
# 4 Re: struct in class (error c2556)
The problem is that there are may lines of code that have nothing to do with this functions besides that I use some libraries that will make compilation impossible. I managed to localize the problem it is about the declaration and definition of the same function. In your opinion should this work (rest of the program being without an error)?
Thank you
lontana at 2007-11-10 22:25:40 >
# 5 Re: struct in class (error c2556)
Then create a new test project only with this "clas A" and its method f (and without "some libraries" and so on, of course. If the error c2556 will still be there - post your code (or the complete project in zip archive).
VictorN at 2007-11-10 22:26:38 >
# 6 Re: struct in class (error c2556)
1) There are numerous typos in your code.

2) the following should compile:

#include <vector>

class A
{
struct st
{
int a,b;
};
protected:
std::vector<st> f(int d, int c, int g);

;

std::vector<A::st> A::f(int d, int c, int g)
{
st s;
std::vector<st> v;
for(int i=0;i<d;i++)
{
s.a=c+i;
s.b=g-i;
v.push_back(s);
}
return v;
}
Philip Nicoletti at 2007-11-10 22:27:41 >