Using the entered class name to call member functions

In Calling the static method, repeating the name of the object , I see the following code.

struct foo {
  static foo& instance() {
    static foo f;
    return f;
  }
};

and

foo::foo::foo::instance();

works great.

However, in the expected type specifier and cannot convert 'int * to initialization , I see the following code:

namespace ASP
{
    class ASp
    {
        public:
            ASp();
            ASp(FILE* fp);  
    };
}

But

using namespace ASP;
ASp* asp = new ASp::ASp();

cannot compile in g ++ 4.8.2 and Visual Studio 2010.

g ++ reports:

error: expected type-specifier
 ASp* asp = new ASp::ASp();

Visual Studio Reports:

error C2061: syntax error : identifier '{ctor}'

Why does the entered class name work for the first case, and not for the second case?

+4
source share
1 answer

I think GCC gives a pretty useful hint:

error: expected type-specifier

An operator newimmediately expects a type name, not a constructor name.

ASp::ASp , . ++ , : , . , typename ( ooga!), struct class ( ::, ):

using namespace ASP;
ASp* asp = new class ASp::ASp();
+4

All Articles