No matching function for call error with a function never called?
Oct 20, 2017 at 8:28pm UTC
I have a World class in my game that holds an array of "Regions" called _map. In the for loop to populate this array, the constructor for region takes one integer for the seed. In the header file the constructor is declared correctly as far as I can see.
maps.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "maps.h"
#include <ctime>
#include <cstdlib>
#include "efuncs.h"
Region::Region(int seed)
{
srand(seed);
biome = generateBiome(rand()%8);
playerCoord.X = 4;
playerCoord.Y = 4;
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
_map[x][y] = genLand(biome, rand() % 100);
}
}
}
World::World(int seed)
{
cout << "Generating world..." << endl;
srand(seed);
playerlocation.Y = 4;
playerlocation.X = 4;
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
int newseed = rand();
_map[x][y] = Region(newseed);
}
}
}
maps.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#ifndef MAPS_H_
#define MAPS_H_
#include <iostream>
#include <windows.h>
#include "efuncs.h"
using namespace std;
class Region
{
public :
Region(int seed);
void showMap();
char getLand(int ,int );
char getBiome();
char getPlayerLand();
int playerx();
int playery();
private :
char biome;
char _map[10][10];
COORD playerCoord;
};
class World
{
public :
World(int );
void displayMap();
Region _map[10][10];
int playerx();
int playery();
private :
COORD playerlocation;
};
#endif // MAPS_H_
I have omitted some of the other functions used in the constructors for size purposes.The error I am getting is:
D:\WorldGame\maps.cpp|243|error: no matching function for call to 'Region::Region()'|
Oct 20, 2017 at 8:46pm UTC
Which is the line of code (line 243?) it's complaining about?
Oct 20, 2017 at 8:48pm UTC
On line 32 of maps.h you declare World::_map, which is an array of Regions. You can't declare arrays whose elements are of a type that doesn't have a default constructor.
Oct 21, 2017 at 9:45pm UTC
Oh, I didn't know I needed to do that, but now that I think about it, it makes sense I would need to do that. That fixed it, thanks much!
Topic archived. No new replies allowed.