I have some C++ code I am working on that receives the following compilation error:
Code:
game.cpp:29:11: error: expected constructor, destructor, or type conversion before ‘(’ token
Game::Game(date, true, boxCount)
I cannot seem to find the reason this is occurring, because this is how a constructor is supposed to be. Any advice would be greatly appreciated.
box.h
Code:
#ifndef BOX_H
#define BOX_H
#include <string>
class Box
{
friend std::ostream& operator<<(std::ostream& o, const Box& b);
friend bool operator<(const int i, const Box& b);
friend bool operator==(const int i, const Box& b);
friend int operator+(const int i, const Box& b);
public:
Box(std::string d, bool f, int bc);
bool operator<(const Box& b) const;
protected:
std::string date;
int productCount;
int boxCount;
bool isFull;
box.cpp
Code:
#include <iostream>
#include <string>
#include "box.h"
using namespace std;
Box::Box(string d, bool f, int bc)
:date(d)
,boxCount(bc)
,productCount()
,isFull(f)
{
}
ostream& operator<<(ostream& o, const Box& b)
{
return o << "Box[" << b.productCount << "]";
}
bool operator<(const int i, const Box& b)
{
return i < b.productCount;
}
bool operator==(const int i, const Box& b) {
return i == b.productCount;
}
int operator+(const int i, const Box& b) {
return i + b.productCount;
}
bool Box::operator<(const Box& b) const
{
return productCount < b.productCount;
}
game.h
Code:
#ifndef GAME_H
#define GAME_H
#include <string>
#include "box.h"
class Game : public Box
{
friend std::ostream& operator<<(std::ostream& o, const Game& b);
friend bool operator<(const int i, const Game& b);
friend bool operator==(const int i, const Game& b);
friend int operator+(const int i, const Game& b);
public:
Game(std::string, bool, int);
};
#endif
game.cpp
Code:
#include <iostream>
#include <string>
#include "game.h"
#include "box.h"
using namespace std;
Game::Game(date, true, boxCount)
:Box(date, true, boxCount)
,productCount(6)
{
}