Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derived class in a different namespace [closed]

Tags:

c++

Is there any recommendation against creating a derived in a different namespace than of its parent? Such as:

namespace NA {
class A {};
}

namespace NB {
class B : NA::A {}
}
like image 244
Bernardo Reis Avatar asked Jan 17 '26 19:01

Bernardo Reis


1 Answers

Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.

If you think class A and class B should have under different namespaces (groups), kept them under different namespaces (groups). And when you need to access/ inherit one class from another, you just access/ inherit it following namespace standard.

I don't see any problems here, rather it is a good practice.

Thanks !

like image 71
Monirul Islam Milon Avatar answered Jan 20 '26 10:01

Monirul Islam Milon