Re: basic question on c++ linking
On Jun 29, 1:10 pm, Peskov Dmitry <vamsi.kom...@gmail.com> wrote:
On Jun 29, 3:04 pm, James Kanze <james.ka...@gmail.com> wrote:
[...]
Let me put my question differently ? which one below
a)
class new_class;
or
b)
class new_class
{
int a;
public:
new_class();
};
is a class declaration ?
Both. The second is also a definition. (A definition is a
declaration, but the reverse is not necessarily true.)
Because if i include (b) in my code as this one it works.
That's because the way you used the class required a definition.
using namespace std;
#include <iostream>
class new_class
{
int a;
public:
new_class();
};
int main(){
new_class st1;
return 0;
}
I assume class definition includes the function that you are defining
something like
class new_class
{
int a;
public:
new_class();
};
A class definition includes the contents (members) of the class.
new_class::new_class
{
a = 10;
}
is a class definition ?
No, that's a syntax error.
A class definition is:
class <name> <baseclass-declarations>[opt] { ... } ;
A class declaration (which isn't also a definition) is just:
class <name> ;
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34