Returning a struct from a class method
Posted
by
tree
on Stack Overflow
See other posts from Stack Overflow
or by tree
Published on 2012-04-14T05:24:59Z
Indexed on
2012/04/14
5:28 UTC
Read the original article
Hit count: 86
I have a header file that looks something like the following:
class Model {
private:
struct coord {
int x;
int y;
} xy;
public:
....
coord get() const {
return xy;
}
};
And in yet another file (assume ModelObject exists):
struct c {
int x;
int y;
void operator = (c &rhs) {
x = rhs.x;
y = rhs.y;
};
} xy;
xy = ModelObject->get();
The compiler throws an error that says there is no known covnersion from coord to c. I believe it is because it doesn't know about coord type because it is declared inside of a class header. I can get around that by declaring the struct outside of the class, but I was wondering if it is possible to do the way I am, or is this generally considered bad practice
© Stack Overflow or respective owner