[英]function cannot be overloaded error c++
I'm learning composition by making a connect 4 game that has a column class within a board class. 我正在学习通过制作在棋盘类中具有专栏类的Connect 4游戏来学习构图。 I have spent forever trying to figure out these overloading errors:
我花了很多时间试图找出这些重载错误:
g++ -g -c C4Board.cpp -o C4Board.o
C4Board.cpp:11:1: error: ‘C4Board::C4Board()’ cannot be overloaded
C4Board(){
^
In file included from C4Board.cpp:9:0:
C4Board.h:7:5: error: with ‘C4Board::C4Board()’
C4Board();
^
C4Board.cpp:20:1: error: ‘C4Board::~C4Board()’ cannot be overloaded
~C4Board(){}
^
In file included from C4Board.cpp:9:0:
C4Board.h:9:5: error: with ‘C4Board::~C4Board()’
~C4Board();
^
C4Board.cpp:20:12: error: expected ‘}’ at end of input
~C4Board(){}
^
Here are my constructors: 这是我的构造函数:
#include <iostream>
using namespace std;
#include "C4Col.h"
#include "C4Board.h"
C4Board(){
numCol = 7;
}
C4Board(int columns){
numCol = columns;
}
~C4Board(){}
I got rid of the C4Board::
before the constructors because it gave me this error in addition to the overloading errors: 我摆脱了
C4Board::
在构造函数之前,因为它除了重载错误外还给了我这个错误:
error: extra qualification ‘C4Board::’ on member ‘C4Board’ [-fpermissive]
C4Board::C4Board(){
^
Here is my .h file, although I don't believe it's the problem: 这是我的.h文件,尽管我不认为这是问题所在:
class C4Board{
public:
C4Board();
C4Board(int);
~C4Board();
void display();
void play();
private:
int numCol;
C4Col Board[7];
}
Any help would be greatly appreciated. 任何帮助将不胜感激。
compiler is recognizing functions as different, you have to specify that these are the definitions of your class methods... 编译器将函数识别为不同函数,您必须指定这些是您的类方法的定义...
C4Board::C4Board(){
numCol = 7;
}
C4Board::C4Board(int columns){
numCol = columns;
}
C4Board::~C4Board(){}
If that really is your .h file, it's missing a final }
. 如果这确实是您的.h文件,那么它将缺少final
}
。 That can give these symptoms. 那可以给这些症状。
Remember that the #include
can be seen as putting the entire text of the .h file into the .cpp file. 请记住,
#include
可以看作是将.h文件的整个文本放入.cpp文件中。 A missing final }
results in your function definitions from the .cpp file being inside the class definition from the .h file. 缺少最终的
}
导致.cpp文件中的函数定义位于.h文件中的类定义内 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.