terms of importance

E

eas

Are the following comments all correct? Thanks in advance!

/*declaration and definition of myconst?*/
const int myconst = 4567;

/*declaration of myclass only?*/
class myclass;

/*definition of myclass?*/
class myclass
{
/*definition of mystatic?*/
static int mystatic;
/*declaration?*/
void mymethod();
};

/*initialization of mystatic?*/
int myclass::mystatic = 7890;

/*definition of mymethod?*/
void myclass::mymethod() { ... }


int main()
{
/*delcaration and definition of myobject?*/
myclass myobject;
return 0;
}
 
S

Simon Bachmann

eas said:
Are the following comments all correct? Thanks in advance!

/*declaration and definition of myconst?*/
const int myconst = 4567;

/*declaration of myclass only?*/
class myclass;

/*definition of myclass?*/
class myclass
{
/*definition of mystatic?*/
static int mystatic;
/*declaration?*/
void mymethod();
};

/*initialization of mystatic?*/
int myclass::mystatic = 7890;

/*definition of mymethod?*/
void myclass::mymethod() { ... }

int main()
{
/*delcaration and definition of myobject?*/
myclass myobject;
return 0;
}

It seems to me you're right...
 
V

Victor Bazarov

eas said:
Are the following comments all correct? Thanks in advance!

/*declaration and definition of myconst?*/
const int myconst = 4567;

declaration, definition, _and_ initialisation.
/*declaration of myclass only?*/
class myclass;

Also known as "forward-declaration".
/*definition of myclass?*/
class myclass
{
/*definition of mystatic?*/
static int mystatic;

No, declaration of 'mystatic'.
/*declaration?*/
void mymethod();

Yes. Most of the things inside a class definition are declarations.
};

/*initialization of mystatic?*/
int myclass::mystatic = 7890;

No, _definition_ _and_ initialisation of myclass::mystatic.
/*definition of mymethod?*/
void myclass::mymethod() { ... }
Yes.



int main()
{
/*delcaration and definition of myobject?*/
myclass myobject;
Yes.

return 0;
}

HTH

V
 
A

Andrey Tarasevich

eas said:
Are the following comments all correct? Thanks in advance!

/*declaration and definition of myconst?*/
const int myconst = 4567;
Yes.

/*declaration of myclass only?*/
class myclass;
Yes.

/*definition of myclass?*/
class myclass
Yes.

{
/*definition of mystatic?*/
static int mystatic;

No. This is declaration.
/*declaration?*/
void mymethod();
Yes.

};

/*initialization of mystatic?*/
int myclass::mystatic = 7890;

It is definition of 'myclass::mystatic'. It also contains an initializer.
/*definition of mymethod?*/
void myclass::mymethod() { ... }
Yes.

int main()
{
/*delcaration and definition of myobject?*/
myclass myobject;

Yes. It is sufficient to say that this is definition of 'myobject'.
 
T

The Directive

Victor,

Victor Bazarov said:
declaration, definition, _and_ initialisation.


Also known as "forward-declaration".


No, declaration of 'mystatic'.


Yes. Most of the things inside a class definition are declarations.

Can you give the examples of when things inside a class definition
are not declarations?

--The Direvtive
 
R

Rolf Magnus

The said:
Can you give the examples of when things inside a class definition
are not declarations?

Depends on what you define as 'thing', but e.g.

public:

is not a delcaration.
 
V

Victor Bazarov

The Directive said:
Victor,



Can you give the examples of when things inside a class definition
are not declarations?

Yes, I can. Oh, did you mean to ask me to give such example?

class A {
class Nested {
int a;
};
};

The 'Nested' is a _definition_ inside the class A definition. More?

class A {
enum E { A, B, C };
};

'A', 'B', and 'C' are _definitions_ of enumerators inside the class A
definition.

Of course, one can have a member function _defined_ right there, in
a class definition, but you already knew that...

Victor
 
A

Andrey Tarasevich

Victor said:
Yes, I can. Oh, did you mean to ask me to give such example?

class A {
class Nested {
int a;
};
};

The 'Nested' is a _definition_ inside the class A definition. More?

class A {
enum E { A, B, C };
};

'A', 'B', and 'C' are _definitions_ of enumerators inside the class A
definition.

Of course, one can have a member function _defined_ right there, in
a class definition, but you already knew that...
...

Yes, but formally speaking the definitions given in your examples are
both definitions and declarations at the same time, while it appears
that the previous poster was looking for something that is not a
declaration. Although it could be just a bad wording on his part...
 
V

Victor Bazarov

Andrey Tarasevich said:
Yes, but formally speaking the definitions given in your examples are
both definitions and declarations at the same time, while it appears
that the previous poster was looking for something that is not a
declaration. Although it could be just a bad wording on his part...

I seem unable to think of a definition that is _not_ simultaneously
a declaration. Can you name a couple? Thanks.

V
 
J

Jonathan Turkanis

Victor Bazarov said:
part...

I seem unable to think of a definition that is _not_ simultaneously
a declaration. Can you name a couple? Thanks.

How about

void dog::bark() { std::cout << "woof!\n"; }

Jonathan
 
A

Andrey Tarasevich

Victor said:
I seem unable to think of a definition that is _not_ simultaneously
a declaration. Can you name a couple? Thanks.
...

I don't think I can, especially if we take into account the fact that
the defition of the term "definition" in the standard (3.1/2) begins
with "A 'declaration' is a 'definition' unless ..."
 
A

Andrey Tarasevich

Jonathan said:
How about

void dog::bark() { std::cout << "woof!\n"; }
...

From the formal point of view, this is still a declaration. 7.1 refers
to 'function-definition' as one form of declaration. And
'function-definition' includes definitions of both standalone functions
and and member functions. Of course, this is not a self-sufficient
declaration, meaning that the function must also be declared in the
class definition, but declaration nevertheless.
 
J

Jonathan Turkanis

Andrey Tarasevich said:
Jonathan Turkanis wrote:

From the formal point of view, this is still a declaration. 7.1 refers
to 'function-definition' as one form of declaration. And
'function-definition' includes definitions of both standalone functions
and and member functions. Of course, this is not a self-sufficient
declaration, meaning that the function must also be declared in the
class definition, but declaration nevertheless.

Yeah, you got me. :( The standard implicitly states that all
definitions are declarations in 3.1/2.

Okay, I'll give it one last try:

#define THIS_IS_A_DIRECTIVE but also a definition ;-)

Jonathan
 
R

Risto Lankinen

The Directive said:
Can you give the examples of when things inside a class definition
are not declarations?

Implicit inline functions for one:

class C
{
int f() { return 101; } // <- definition
};


- Risto -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top