I have a class that has a 2D array of objects, but it throws an error when I call a function to set the object to a new one.
Here's my game class. It's simple and not very large.
#include <iostream>
#include <stdio.h>
#include "room.hpp"
class Game
{
private:
Room map[50][50];
public:
Game(std::string title);
~Game()=default;
void add_room(int x, int y);
void trace(std::string text);
};
And here's my game.cpp. The error happens in the add_room() function. I have the proper imports and everything. No idea what's wrong.
#include <iostream>
#include <stdio.h>
#include "game.hpp"
#include "room.hpp"
Game::Game(std::string name)
{
trace(name);
}
void Game::add_room(int x, int y, Room r)
{
map[x][y]=r;
}
void Game::trace(std::string text)
{
printf("%s\n", text.c_str());
}
Here's my Room class
#ifndef Room_H
#define Room_H
class Room
{
private:
std::string name;
std::string desc;
public:
Room(std::string n, std::string d);
~Room()=default;
};
#endif
And here's the cpp
#include <iostream>
#include <stdio.h>
#include "room.hpp"
Room::Room(std::string n, std::string d)
{
name=n;
desc=d;
}
Here's the error anyway:
../TAGE/game.cpp: In constructor 'Game::Game(std::string)':
../TAGE/game.cpp:6:28: error: no matching function for call to 'Room::Room()'
Game::Game(std::string name)
^
../TAGE/game.cpp:6:28: note: candidates are:
In file included from ../TAGE/game.hpp:6:0,
from ../TAGE/game.cpp:3:
../TAGE/room.hpp:11:3: note: Room::Room(std::string, std::string)
Room(std::string n, std::string d);
^
../TAGE/room.hpp:11:3: note: candidate expects 2 arguments, 0 provided
../TAGE/room.hpp:5:7: note: Room::Room(const Room&)
class Room
^
../TAGE/room.hpp:5:7: note: candidate expects 1 argument, 0 provided
../TAGE/game.cpp: In constructor 'Game::Game(std::string)':
../TAGE/game.cpp:6:28: error: no matching function for call to 'Room::Room()'
Game::Game(std::string name)
^
../TAGE/game.cpp:6:28: note: candidates are:
In file included from ../TAGE/game.hpp:6:0,
from ../TAGE/game.cpp:3:
../TAGE/room.hpp:11:3: note: Room::Room(std::string, std::string)
Room(std::string n, std::string d);
^
../TAGE/room.hpp:11:3: note: candidate expects 2 arguments, 0 provided
../TAGE/room.hpp:5:7: note: Room::Room(const Room&)
class Room
^
../TAGE/room.hpp:5:7: note: candidate expects 1 argument, 0 provided