1

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.

2
  • 1
    I got rid of the C4Board:: before the constructors you need to have it in the .cpp Commented Feb 1, 2017 at 6:37
  • 3
    Now you have edited your question and changed the .h file. It is still wrong (missing a semicolon at the end), but have you tested that your change didn't fix the errors that you are asking about? Commented Feb 1, 2017 at 7:00

2 Answers 2

1

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(){} 
Sign up to request clarification or add additional context in comments.

Comments

0

If that really is your .h file, it's missing a 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. A missing final } results in your function definitions from the .cpp file being inside the class definition from the .h file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.