Use of Elaborated Type Specifier to create object of hidden class

70 views Asked by At

I have following code snippet :

    namespace A {
      class X { 
          X()
          {
              std::cout<< " I am here in Constructor";      
          }

          };
    }
    namespace B 
    {

      void X(int)
      {

         std::cout << " I am in a function"; 

      };
    }
    using A::X;
    using B::X;

    void f() {
      X(1);   //Will call B::X(int) func          
    }


    int main()
    {

        f();  
        class X x;
        return 0;
    }

Following statements hides class A::X according to section 3.3.10

using A::X;
using B::X

But class should be accessed with a Elaborated type specifier and following statements should perfectly create an object:

class X x;

But it is giving error :

In function 'int main()': 38:13: error: aggregate 'main()::X x' has incomplete type and cannot be defined

Live Demo - http://cpp.sh/4bm4

What is wrong here??

Am i misunderstanding something ??

0

There are 0 answers