S
Spiffy
When I created a function to return a pointer to a Struct, GCC returns
"error: cannot convert ‘linklist::node*’ to ‘node linklist::*’ in
return" about the return line. I have tried a bunch of things to no
avail. This is a three part question.
1) What it would take to get the code below to compile?
2) How come within this function, I needed to specify class name
when referring to the Struct, while other public or private function
doesn't have to?
3) Ideally, I would keep the Struct private, but that caused more
compiler error. Is this possible?
Thanks!
class linklist {
public:
struct node {
int data;
node *link;
};
linklist();
~linklist();
void append( int num );
private:
struct node *p;
struct node *addnode( int num );
};
struct node linklist::*addnode ( int num ) {
linklist::node *t;
// cut...
return (linklist::node*)t;
}
void linklist::append( int num ) {
"error: cannot convert ‘linklist::node*’ to ‘node linklist::*’ in
return" about the return line. I have tried a bunch of things to no
avail. This is a three part question.
1) What it would take to get the code below to compile?
2) How come within this function, I needed to specify class name
when referring to the Struct, while other public or private function
doesn't have to?
3) Ideally, I would keep the Struct private, but that caused more
compiler error. Is this possible?
Thanks!
class linklist {
public:
struct node {
int data;
node *link;
};
linklist();
~linklist();
void append( int num );
private:
struct node *p;
struct node *addnode( int num );
};
struct node linklist::*addnode ( int num ) {
linklist::node *t;
// cut...
return (linklist::node*)t;
}
void linklist::append( int num ) {