Is it possible to add an object to a namespace in c++ so i can access its variables simply by writing the name of the variable and without the need of writing the name of the object followed by dot and then the variable name?
1 Answer
Dot? In C++, namespaces are descriminated using the scope resolution operator ::; for example std::string tells you that the string class is in std.
if you write the statement using namespace /*your namespace here*/ then you can drop the explicit namespace reference and the ::.
3 Comments
Red Alert
you misinterpreted his question. He wants to be able to do something like
std::string stringObj = "test"; using stringObj; size_t s = size(); //<-- refers to stringObj.size(). Not something I'd consider proper class usage, but whatever.Bathsheba
I may well have done: let's wait for any clarification. But OP does mention namespace twice and once in the title.
Red Alert
He clearly says "without the need of writing the name of the object followed by dot and then the variable name". He wants it to function like using a namespace, which is why that is mentioned (and probably the fact that he doesn't really understand what a namespace is).
Withkeyword from VBA?