Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When defining a function, are you also declaring it?

Tags:

c++

When defining a function in the class body, are you always declaring it or how would you say? Here is an example:

class ss 
{
ss() {}
};

Are we then declaring the constructor, defining the constructor, or declaring AND defining the constructor. What could you say about this?


1 Answers

You're both declaring and defining the constructor.

A declaration only would look like:

class ss 
{
  ss();
}

You can seperate the definition and declaration outside the class to show the obvious difference between the two:

class ss 
{
  ss(); //declaration
}

ss::ss() {} // definition

A definition is by definition a declaration too.

A declaration is only the signature of a function, a definition includes the actual function body.

like image 183
Hatted Rooster Avatar answered Aug 21 '26 01:08

Hatted Rooster