Can I put a class into a namespace?

D

Daqian Yang

Hello all,

can I do this in cpp:

namespace name{
class classname{
//fuctions here...
}
}

thanks.
 
G

Gianni Mariani

Daqian said:
Hello all,

can I do this in cpp:

namespace name{
class classname{
//fuctions here...
}
}

Yes. You can nest classes within classes and functions and you can nest
namespaces within namespaces.

i.e.

namespace X {
namespace Y {
struct A {
struct B {
void F() {
class C {};
}
};
};
};
};
 
M

Michael Mellor

Gianni said:
Yes. You can nest classes within classes and functions and you can nest
namespaces within namespaces.

i.e.

namespace X {
namespace Y {
struct A {
struct B {
void F() {
class C {};
}
};
};
};
};
but don't put semicolons after namespaces because it isn't standard
conforming.

namespace X {
namespace Y {
struct A {
struct B {
void F() {
class C {};
}
};
};
}
}

Michael Mellor
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top