I'm learning composition by making a connect 4 game that has a column class within a board class. 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:
error: extra qualification ‘C4Board::’ on member ‘C4Board’ [-fpermissive] C4Board::C4Board(){ ^ Here is my .h file, although I don't believe it's the problem:
class C4Board{ public: C4Board(); C4Board(int); ~C4Board(); void display(); void play(); private: int numCol; C4Col Board[7]; } Any help would be greatly appreciated.
I got rid of the C4Board:: before the constructorsyou need to have it in the .cpp