I'm trying to define a class this way (simplified):
class Student
{
private:
Student* pointer;
public:
set_pointer(Student*);
}
Is this legal in C++ and is it consistent with object oriented design?
I'm trying to define a class this way (simplified):
class Student
{
private:
Student* pointer;
public:
set_pointer(Student*);
}
Is this legal in C++ and is it consistent with object oriented design?
Yes, a class may store a pointer to an object of the same type (which may be itself, or some other instance).
This is common in linked-list implementations, where a node stores a pointer to the next node.
As for whether it's "consistent with object oriented design", it is impossible to make a generalisation on the subject; it depends on the program. Personally I cast a suspicious eye on code of this form, but again you can't really generalise.