Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Here is the error
Code:
cLevel.h:19: error: no matching function for call to 'cTile::cTile()'
cTile.h:21: note: candidates are: cTile::cTile(SDL_Surface*, int, int, int)
cTile.h:8: note:                 cTile::cTile(const cTile&)

Here's the sources:
cLevel.h
Code:
//Shawn Barnes
//June 3rd, 2006
#ifndef __CLEVEL_H_
#define __CLEVEL_H_

#include <iostream.h>
#include <fstream.h>
#include "cTile.h"

class cLevel {

private:
	SDL_Surface* m_Bitmap;
	SDL_Surface* m_Window;
	cTile m_Tiles[WTILE_HEIGHT][WTILE_WIDTH];

public:
	cLevel(SDL_Surface* window, SDL_Surface* lBitmap)
	{
		m_Window = window;
		m_Bitmap = lBitmap;
		Load("data/test.txt");
	}

	~cLevel() { }
	//asdf
	void Load(char* level)
	{
		ifstream input_stream(level);
		int dummy[3];
		int input_tile_type;
		input_stream >> dummy[0];
		input_stream >> dummy[1];
		input_stream >> dummy[2];
		for(int col = 0; col < WTILE_HEIGHT; col++)
		{
			for(int row = 0; row < WTILE_WIDTH; row++)
			{
				input_stream >> input_tile_type;
				m_Tiles[col][row] = cTile(m_Bitmap, row*TILE_WIDTH, col*TILE_HEIGHT, (int)input_tile_type);
			}
		}
	}
		
	void Draw()
	{
		for(int col = 0; col < WTILE_HEIGHT; col++)
		{
			for(int row = 0; row < WTILE_WIDTH; row++)
			{
				m_Tiles[col][row].Draw(m_Window);
			}
		}
	}

};

#endif

cTile.h
Code:
//cTile by Shawn Barnes
//Date: June 3rd, 2006
//Thanks for Aaron Cox for the help

#ifndef __CTILE_H_
#define __CTILE_H_

class cTile {

private:
	int m_ImageX;
	int m_ImageY;
	int m_Width;
	int m_Height;
	int m_Type;
	int dstX;
	int dstY;
	SDL_Surface* m_Tile;
	
public:
	cTile(SDL_Surface* bitmap, int dx, int dy, int type) : 
	m_Tile(bitmap), dstX(dx), dstY(dy), m_Type(type)
	{
		SDL_Rect r = TileTypeRect(type);
		m_ImageX = r.x;
		m_ImageY = r.y;
		m_Width = r.w;
		m_Height = r.h;
		m_Type = type;
		m_Tile = bitmap;
	}
	
	~cTile()
	{
		SDL_FreeSurface(m_Tile);
	}
	
	SDL_Rect TileTypeRect(int type)
	{
		SDL_Rect tile_rect;
		
		switch(type)
		{
			case 1:
				tile_rect.x = 0;
				tile_rect.y = 0;
				tile_rect.w = 32;
				tile_rect.h = 32;
			break;
			default:
			break;
		}
		
		return tile_rect;
	}
	
	int GetType()
	{
		return m_Type;
	}
	
	void SetImageLocation(int x, int y)
	{
		m_ImageX = x;
		m_ImageY = y;
	}
	
	void Draw(SDL_Surface* window)
	{
		SDL_Rect source = { m_ImageX, m_ImageY, m_Width, m_Height };
		SDL_Rect destination = { dstX, dstY, m_Width, m_Height };
		SDL_BlitSurface(m_Tile, &source, window, &destination);
	}
	
};

#endif

If I remove the cLevel constructor (which I need) the error disappears and compiles perfectly.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
What the heck, I can't declare cTile as an array ? its saying I have to initialize it but I can't/you can't. What am I doing wrong here?

EDIT: I got it, I added cTile() { } after the first instance of cTile(...args...) { ... }
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
I haven't been involved with SDL, but I can give you some advice: Do NOT use <iostream.h> and <fstream.h> because they are deprecated. They don't even support all the functions that the newer versions have. Use <iostream> and <fstream> instead. Then, use the std namespace with the command "use namespace std" (in case you need many commands from that namespace).
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Soulstorm said:
I haven't been involved with SDL, but I can give you some advice: Do NOT use <iostream.h> and <fstream.h> because they are deprecated. They don't even support all the functions that the newer versions have. Use <iostream> and <fstream> instead. Then, use the std namespace with the command "use namespace std" (in case you need many commands from that namespace).
Wait there's a difference between iostream.h and iostream? when did this happen?
 

ozubahn

macrumors regular
Feb 15, 2003
100
0
Connecticut
You need a default constructor.

Hi there. The compiler is complaining because you don't have a default cTile::cTile() constructor, and it needs one in order to construct cLevel. The compiler normally produces a default constructor for any given class automatically as long as you haven't defined any other constructors. cTile does have a non-default constructor defined in this case, so cTile::cTile() ceases to exist unless you provide it explicitly. I am not sure I understand why the error goes away when you remove cLevel's constructor, because I think a default cTile::cTile() will still be necessary, but perhaps someone else can weigh in on that.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
ozubahn said:
Hi there. The compiler is complaining because you don't have a default cTile::cTile() constructor, and it needs one in order to construct cLevel. The compiler normally produces a default constructor for any given class automatically as long as you haven't defined any other constructors. cTile does have a non-default constructor defined in this case, so cTile::cTile() ceases to exist unless you provide it explicitly. I am not sure I understand why the error goes away when you remove cLevel's constructor, because I think a default cTile::cTile() will still be necessary, but perhaps someone else can weigh in on that.

If I have two constructors, function overloading, it works.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
slooksterPSV said:
Wait there's a difference between iostream.h and iostream? when did this happen?
It happened when the namespaces were firstly introduced in C++. Yes, there are many differences between <iostream> and <iostream.h> and the later is considered deprecated (otherwise, why would they be named differently?), so it is recommended to avoid using <iostream.h>.

You can verify that when you try to include <iostream.h> into Xcode, which will complain that iostream.h is deprecated and you shouldn't use it.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Soulstorm said:
It happened when the namespaces were firstly introduced in C++. Yes, there are many differences between <iostream> and <iostream.h> and the later is considered deprecated (otherwise, why would they be named differently?), so it is recommended to avoid using <iostream.h>.

You can verify that when you try to include <iostream.h> into Xcode, which will complain that iostream.h is deprecated and you shouldn't use it.
If I'm thinking right, this also works with stack and many others.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
slooksterPSV said:
If I'm thinking right, this also works with stack and many others.
yes. Warnings also come out when using old-type STL libraries such as <map.h>. The current way of calling them is to call them with their new names, without the .h extension and using the std namespace.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.