|
Written like this, you can compile
class ilist_item {
public:
ilist_item (int value, ilist_item * item = 0);
~ ilist_item () {};
private:
int _value;
ilist_item * _next;
};
class ilist {
public:
ilist (): _ at_front (0), _ at_end (0), _ size (0) ()
void insert (ilist_item * ptr, int value);
int size ();
private:
// Prevent calling these two functions, causing unnecessary errors
ilist (const ilist&);
ilist&operator = (const ilist&);
ilist_item * _at_front; // A pointer is defined and the constructor is not called
ilist_item * _at_end;
int _size;
};
If you write it like this, it will prompt that ilist_item has no constructor when compiling:
class ilist_item;
class ilist {
public:
ilist (): _ at_front (0), _ at_end (0), _ size (0) ()
void insert (ilist_item * ptr, int value);
int size ();
private:
// Prevent calling these two functions, causing unnecessary errors
ilist (const ilist&);
ilist&operator = (const ilist&);
ilist_item * _at_front; // A pointer is defined and the constructor is not called
ilist_item * _at_end;
int _size;
};
class ilist_item {
public:
ilist_item (int value, ilist_item * item = 0);
~ ilist_item () {};
private:
int _value;
ilist_item * _next;
};
But why doesn't it prompt me to repeat the definition error?
Change the class ilist_item; to:
extern class ilist_item;
A warning appears: warning C4091: "extern": Ignore left side of "ilist_item" when no variable is declared
What does this warning mean? |
|