How to use namespace in C++?
Answer:
Let us see a namespace “Test”,
namespace Test { class TestObject { public: void DoSomething() {} }; void Func(TestObject) {} }
Now let see three ways to access the members of the namespace “Test”.
Test::TestObject test; test.DoSomething(); Test::Func(test);
using Test::TestObject; TestObject test; test.DoSomething();
using namespace Test; TestObject test; test.DoSomething(); Func(test);
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Answer:
Let us see a namespace “Test”,
Now let see three ways to access the members of the namespace “Test”.
1, Use the fully qualified name:
2. Use a using-declaration to bring one identifier into scope:
3. Use a using directive to bring everything in the namespace into scope:
need an explanation for this answer? contact us directly to get an explanation for this answer