Can member function arguments of the same class type?

//node.h 
class node 
{
      public:
            void sort(node n);

};

I have not tried the code yet. But it is interesting to know if this is a real 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) ;
}
+3
source share
5 answers

Having established that your question is exclusively related to passing nodeby value in a member (instead of passing node*or node&), the answer is still yes. You can even define a member body inside a class, so you want.

, . , , , , . , node . , , , node.

( ).

+4

, . , ?

, , , /.

struct Foo
{
  Foo m_foo;
};

, , :

struct Foo
{
  Foo m_foo;
  Foo m_bar;
};

foo 2 Foos, 4 Foos, 8 Foos .., .

, :

struct Foo
{
  Foo* m_foo;
};

Foo Foo. - , , , .

+5

, . .

++:

string& append( const string& str );
+2

. :

class Apple {  
public:  
    Apple();  
    Apple(const Apple&);  
};  
0

: :

Long answer:

$ 9.2 / 2- "A class is considered a completely defined type of an object (3.9) (or a full type) when closing} a class specifier. Inside a class, a specification member, a class is considered complete in body functions, default arguments and constructor ctor initializers (including such things in nested classes). Otherwise, it is considered to be an incomplete specification member in its class. "

0
source

Source: https://habr.com/ru/post/1762051/


All Articles