Modules Design in C++ -


i'm new in website , want ask questions c++ because i'm learning these days , i'm noob (i know c , java).

i'm using stroustrup book still don't understand uses , differences between classes , namespaces.

also did c programs subject (operating systems) , want join of them in c++ program. idea have creat modules (because programs rely on different purpose). , have "main.cpp" file it's defined function called several times modules, check if module available , if so, can choose function of module want (depending on parameter passed).

but problem don't know what's better way that. should use? classes or namespaces? , how can design? thought using design following:

main.cpp

--> modulea.cpp (implement interfacea.h)

--> moduleb.cpp (implement interfaceb.h)

--> modulec.cpp (implement interfacec.h)

i searching on web other similar questions , found this one think it's complicate simple program.

thank :)

you won't far namespaces on own :) (as name suggest) provide named-space types prevent pollution of global namespace, , prevent conflict between identical type names. therefore common api have outer namespace containing has, thereby preventing conflicts other apis:

namespace mooslibrary {     typedef boost::uuids::uuid uuid;  // moo's unique identifier! };    namespace anotherlibrary {     typedef int uuid;          // library uses integers unique identifiers }; 

in above snippet, without namespaces, 2 uuid types clash causing untold compilation errors , programming head scratching. however, compartmentalizing them in separate namespaces, can avoid these kinds of type conflict. note in above example, boost::uuids::uuid. there 2 namespaces there.. boost boost c++ library (highly recommended when level of c++!), , uuids namespace within boost dedicated particular part of library.

so, can see not namespaces preventing conflict between types, allows structure projects in logical namespaces global namespace isn't full of types. neat when ide supports intellisense.

namespace mooslibrary {     namespace logic     {         // logic related classes/types     }      namespace ui     {         // user-interface     } } 

note: detail namespace has unwritten-rule associated it. it's api writers put stuff needs publicly visible, not screwed with.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -