//node.h
class node
{
public:
void sort(node n);
};
I didn’t try the code yet . But It’s interesting to know if is this a valid case and Why ?
Edit :
This leads me to another question :
Can I declare FOO inside a member function like this ?
//FOO.h
Class FOO
{
public:
void sort(int n) ;
void swap(int x , int y );
}
//FOO.cpp
void FOO::sort (int n)
{
FOO obj;
obj.swap(3 , 5) ;
}
Having now established that your question is solely related to passing
nodeby value in a member (rather than passingnode*ornode&) the answer is still yes. You can even define the body of the member within the class is you so wish.As to why, think of things from the compiler’s point of view. As it parses the class all it really needs to know are what data members there are within it and what the function member signatures are. None of the function member definitions need to be parsed at this point so the compiler would not be alarmed at the prospect of seeing an actual
nodeas an argument. Only when it’s finished parsing the data and signatures would it go back and actually deal with the function member definitions and at that point it knows precisely what anodeis.In answer to your second question you can define instances of your class within the member (for the same reason).