0

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
  • Do you mean something like the With keyword from VBA? Commented Mar 18, 2014 at 20:54

1 Answer 1

2

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 ::.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
I may well have done: let's wait for any clarification. But OP does mention namespace twice and once in the title.
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.