namespaces

T

Tony Johansson

Hello!

I'm reading a book about C++ and there is something that I don't understand
so I ask you.

It says
"A namespace can contain only the declaration of a member. The corresponding
definitions may be provided outside the namespace; Isn't this wrongit says A
namespace can contain only the declaration of a member. I have definitions
of classes in the namespace even with methods defined and it works.

For example:"

namespace Company
{ class Employee; //class declaration }

class Company::Employee
{
.....
};

//Tony
 
P

Pete Becker

Tony said:
It says
"A namespace can contain only the declaration of a member. The corresponding
definitions may be provided outside the namespace; Isn't this wrongit says A
namespace can contain only the declaration of a member.

It's sloppy writing. Put the emphasis on the second sentence: you can
put definitions outside the namespace if you want to.
 
K

Kanenas

It's sloppy writing. Put the emphasis on the second sentence: you can
put definitions outside the namespace if you want to.

It's also possibly misleading. A definition is a declaration; unless
the author has noted this before and close to the quoted statement,
the sentence is true but will be misread (as the OP has demonstrated).

Kanenas
 
V

Victor Bazarov

Tony said:
I'm reading a book about C++ and there is something that I don't understand
so I ask you.

It says
"A namespace can contain only the declaration of a member. The corresponding
definitions may be provided outside the namespace; Isn't this wrongit says A
namespace can contain only the declaration of a member. I have definitions
of classes in the namespace even with methods defined and it works.

For example:"

namespace Company
{ class Employee; //class declaration }

class Company::Employee
{
....
};

The class 'Employee' is a _member_ of the namespace 'Company'. So, I am
not sure what your complaint is about.

V
 

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

Similar Threads

global namespace 2
#include and namespaces 20
[C#] Extend main interface on child level 0
Namespaces 2
Hwo ca I use optional on map merge? 0
Class Card Deck 0
namespaces 5
"Right" use of namespaces 4

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top