Вопрос

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