質問

I'm trying to declare class as the following:

class MyClass: MyBase;

But I can't because compiler is swearing.

error: expected ‘{’ before ‘;’ token

I'm trying to find a class name declaration to clarify this aspect. But I can't. I'm looking for this in the clause 7 (Declarations) of the c++ working draft.

役に立ちましたか?

解決 2

About standard(n3797):

9.1 Class names:

A class declaration introduces the class name... A declaration consisting solely of class-key identifier; is either a redeclaration of the name in the current scope or a forward declaration of the identifier as a class name. It introduces the class name into the current scope.

10 Derived classes:

A list of base classes can be specified in a class definition...

So, you can just tell the compiler: "Oh, I will define this class later". If you need to know the "structure" of the class then you need to define it.

他のヒント

If you just want to declare the MyClass class, then

class MyClass;

is enough. It tells the compiler that the class MyClass exists, and you can now declare pointers or references to MyClass.

If you want to define the class, then you need to full definition.

Give definition in this way :

class MyClass: MyBase

{

//////

};

If you only want to declare then do in this way :

class MyClass;

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top