Diagram *p[3];
p[0] = new Diagram;
p[1] = new Board;
p[2] = new Pacman;
我聲明基類的指針全球範圍內,同時,我初始化指針與派生類,但是,如果我在全球做給出了一個錯誤,但不當我在Display()函數中聲明指針時。錯誤:C++需要一個類型說明符的所有聲明OOP
clang++ -c -o game-release.o game-release.cpp
game-release.cpp:42:1: error: C++ requires a type specifier for all declarations
p[0] = new Diagram;
^
game-release.cpp:43:1: error: C++ requires a type specifier for all declarations
p[1] = new Board;
^
game-release.cpp:44:1: error: C++ requires a type specifier for all declarations
p[2] = new Pacman;
^
3 errors generated.
make: *** [game-release.o] Error 1
哪個'Display()'函數?你能提供更多的背景嗎?另外,您可能想要添加編譯器錯誤消息。 – evnu
@envu clang ++ -c -o game-release.o game-release.cpp game-release.cpp:42:1:error:C++需要所有聲明的類型說明符 p [0] = new Diagram; ^ game-release.cpp:43:1:error:C++需要所有聲明的類型說明符 p [1] = new Board; ^ game-release.cpp:44:1:error:C++需要所有聲明的類型說明符 p [2] = new Pacman; ^ 生成3個錯誤。 make:*** [game-release.o]錯誤1 – Shaan
請編輯您的問題並在那裏添加輸出。它增強了可讀性。 – evnu