class Foo
{
public:
Foo();
~Foo();
...
};
A class definition instead of a class declaration?
[C++] Terminology: Declaration vs Definition.
When I was coding in C, this distinction was made pretty clear:
- A variable declaration tells the compiler a variable is defined elsewhere
- A variable definition allocates storage and sometimes does initialization.
How come in C++ we call this:
Because it defines the class. However, member functions are only declared here. Class declaration looks like this:
class Foo;
Quote:Original post by rozz666
Because it defines the class.
Well it does "define" the class. But your sentence employs the dictionary definition of the word "define", which contradicts the notion of declaration vs. definition that is inherited from C.
The fact is that no memory is allocated in a class definition (with some small exceptions).
Did C++ just run out of terminology and just repurpose the term "definition"?
It's called definition precisely because it defines the class. In a class definition, the class is fully defined and ready to be use. In a declaration, only its name is introduced.
Compare to functions and variables. A function declaration is only it's header, but a definition is the header and all its code ready to be used. An extern varible declaration only introduces the name as a variable, but in adeclaration you provide storage for it.
So declaration is about "preparing" the name for use, and definition is about providing full definition of its content so you can actually use it.
Compare to functions and variables. A function declaration is only it's header, but a definition is the header and all its code ready to be used. An extern varible declaration only introduces the name as a variable, but in adeclaration you provide storage for it.
So declaration is about "preparing" the name for use, and definition is about providing full definition of its content so you can actually use it.
What is your idea of what declaration and definition mean, fpsgamer? The standards define precisely how the terms apply. The standard definition doesn't use the memory model to explain declaration and definition.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement