| tech junkie (10) | |||
|
I'm reading a book about C++ programming and I'm a little unsure about one thing, the namespaces. I understand that using for example, std::cout access cout in the std namespace but when I took these classes in school, we would always use the dot operator "." Are they interchangeable? They book has for example
The way I read this is that since we are in the Records namespace, to access something in the Employee namespace we must use the :: to get into the Employee namespace. Would this be correct or am I missing something? | |||
|
|
|||
| akrzemi1 (5) | |||||||||
It looks like somewhere earlier in the code you defined a class Employee in namespace Records, e.g. like this:
When referring to member function (rather than just calling it) you have to use :: operator. From global namespace:
Or from inside namespace Records:
Operator :: specifies from which scope we read the names and definitions. It can b a namespace scope, or class scope, or global scope:
I hope that clarifies anything. Regards, &rzej | |||||||||
|
|
|||||||||
| Pyrius (60) | |||
You use the '.' operator if you want to access a function or variable in a class you have an object of. Like this:
That would call the promote function using the empObj object with the int i as the parameter. | |||
|
Last edited on
|
|||