9 Replies - 1900 Views - Last Post: 27 May 2009 - 05:10 PM Rate Topic: -----

#1 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

`c_gui' undeclared (first use this function)

Post icon  Posted 27 May 2009 - 08:42 AM

I'm getting the error `c_gui' undeclared (first use this function) when compiling the following code. It used to compile fine, but after I took out button functions for my gui class and made a separate button class, I started getting this error. I'm not sure what all I changed, but why is it telling me it's undeclared when I'm making all the correct calls and include all the correct header files?

inside of main:
 DATAFILE *my_datafile = NULL;
	my_datafile = load_datafile("datafile.dat");
	if(my_datafile == NULL) {
		set_gfx_mode(GFX_TEXT,0,0,0,0);
		allegro_message("Could not load datafile!");
		exit(EXIT_FAILURE);
	}
 
	c_map map1(32,32,3);
	c_gui gui(my_datafile);


inside of gui.h, the prototype:
c_gui(DATAFILE*);


inside of gui.cpp:
c_gui::c_gui(DATAFILE* t_datafile) {
	map_viewport_x = default_map_viewport_x;
	map_viewport_y = default_map_viewport_y;
	map_viewport_w = default_map_viewport_w;
	map_viewport_h = default_map_viewport_h;
	cur_layer = 0;
	the_datafile = t_datafile;
}

This post has been edited by jkh0208: 27 May 2009 - 08:45 AM


Is This A Good Question/Topic? 0
  • +

Replies To: `c_gui' undeclared (first use this function)

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 10:35 AM

Do both main and the gui cpp files have the appropriate headers?
Was This Post Helpful? 0
  • +
  • -

#3 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 10:43 AM

View PostKYA, on 27 May, 2009 - 09:35 AM, said:

Do both main and the gui cpp files have the appropriate headers?


I put an include for each header file in global.h, and every header file and cpp file include global.h. I've always setup my programs this way and they worked fine in the past, so I'm not sure what I could be doing wrong this time. I even tried putting the .h files for each class in main instead, but it gives me the same error. Would it help if I posted the full source?

By the way, here's my global.h. All my cpp files include global.h:
#ifndef _GLOBAL_H_
#define _GLOBAL_H

//#include <string>
#include <allegro.h>
#include <cstdlib>
#include <iostream>
#include "button.h"
#include "gui.h"
#include "map.h"

#endif

This post has been edited by jkh0208: 27 May 2009 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 11:10 AM

It looks like what you declared and what you're using do not match unless its a typo:

c_gui(DATAFILE*);



Implementation:

c_gui gui(my_datafile);



c_gui vs gui for function call.


Also, if I'm reading correctly, just use the c_gui object to call the function, rather then c_gui gui(DATAFILE). What's the object's name?
Was This Post Helpful? 0
  • +
  • -

#5 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 11:22 AM

View PostKYA, on 27 May, 2009 - 10:10 AM, said:

It looks like what you declared and what you're using do not match unless its a typo:

c_gui(DATAFILE*);



Implementation:

c_gui gui(my_datafile);



c_gui vs gui for function call.


Also, if I'm reading correctly, just use the c_gui object to call the function, rather then c_gui gui(DATAFILE). What's the object's name?



The object's name is gui. I know I should have made it something more descriptive, but it's for testing purposes. If you look at the line above, "c_map map1(32,32,3);", it's just like that. The prototype it c_map's constructor is "c_map(int,int,int);", but the line creating a c_map called map1 compiles fine. That's what I'm trying to do with "c_gui gui(my_datafile);", create an c_gui called gui. Sorry, I'm sort of new to c++. I'm trying to get away from the Blitz family and start using a real programming language for games.

Edit: I tried using the default constructor, calling "c_gui gui;" and still get the same error for that as well.

This post has been edited by jkh0208: 27 May 2009 - 11:23 AM

Was This Post Helpful? 0
  • +
  • -

#6 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 11:44 AM

Could you post your code please? That error indicates that the program cannot find a c_gui description, generally from include file errors or linking problems. Hard to diagnose without looking at it.
Was This Post Helpful? 0
  • +
  • -

#7 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 12:28 PM

View PostKYA, on 27 May, 2009 - 10:44 AM, said:

Could you post your code please? That error indicates that the program cannot find a c_gui description, generally from include file errors or linking problems. Hard to diagnose without looking at it.


main.cpp:
#include "datafile_header.h"
#include "global.h"

int main(int argc, char * argv[]) {
	allegro_init();
	install_keyboard();
	install_mouse();
	
	set_color_depth(15);
	
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0,0);
	
	BITMAP * buffer = create_bitmap(SCREEN_W, SCREEN_H);
	if(buffer == NULL) {
		set_gfx_mode(GFX_TEXT,0,0,0,0);
		allegro_message("Could not create buffer!");
		exit(EXIT_FAILURE);
	}
	
	DATAFILE *my_datafile = NULL;
	my_datafile = load_datafile("datafile.dat");
	if(my_datafile == NULL) {
		set_gfx_mode(GFX_TEXT,0,0,0,0);
		allegro_message("Could not load datafile!");
		exit(EXIT_FAILURE);
	}
 
	c_map map1(32,32,3);
	c_gui gui;
	//c_gui gui(my_datafile);

	while(!key[KEY_ESC]) {
		gui.update(map1);
		gui.draw(buffer, map1);
		gui.get_input(map1);
		
		
		blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		clear(buffer);
	}
	map1.close_map();
	destroy_bitmap(buffer);
	unload_datafile(my_datafile);
	
	return 0;
}
END_OF_MAIN()


gui.h:
#ifndef _GUI_H_
#define _GUI_H_

#include "global.h"

#define default_map_viewport_x 32
#define default_map_viewport_y 32
#define default_map_viewport_w 64 * 8
#define default_map_viewport_h 64 * 6

class c_gui {
	public:
		int cur_layer;
		int map_viewport_x; //left bound of map viewport
		int map_viewport_y; //top bound of map viewport
		int map_viewport_w; //width of map viewport
		int map_viewport_h; //height of map viewport
		int mouse_square_x;
		int mouse_square_y;
		bool mouse_in_map_viewport;
		DATAFILE* the_datafile;

		c_gui();
		c_gui(DATAFILE*);
		
		void draw(BITMAP*, c_map);
		void draw_map(BITMAP*, c_map);
		void get_input(c_map);
		void set_map_viewport(int t_map_viewport_x, int t_map_viewport_y, int t_map_viewport_w, int t_map_viewport_h);
		void update(c_map);

};

#endif


gui.cpp:
#include "datafile_header.h"
#include "global.h"

c_gui::c_gui() {
	map_viewport_x = default_map_viewport_x;
	map_viewport_y = default_map_viewport_y;
	map_viewport_w = default_map_viewport_w;
	map_viewport_h = default_map_viewport_h;
	cur_layer = 0;
}

c_gui::c_gui(DATAFILE* t_datafile) {
	map_viewport_x = default_map_viewport_x;
	map_viewport_y = default_map_viewport_y;
	map_viewport_w = default_map_viewport_w;
	map_viewport_h = default_map_viewport_h;
	cur_layer = 0;
	the_datafile = t_datafile;
}

void c_gui::draw(BITMAP * buffer, c_map map) {
	draw_map(buffer, map);
	if (mouse_in_map_viewport) {
		int i = map_viewport_x + mouse_square_x * map.tile_size;
		int j = map_viewport_y + mouse_square_y * map.tile_size;
		rect(buffer, i , j, i + map.tile_size, j + map.tile_size, makecol(0,255,255));
	}
	rect(buffer, mouse_x, mouse_y, mouse_x + 3, mouse_y + 3, makecol(255,255,255));
}

void c_gui::draw_map(BITMAP * buffer, c_map map) {
	int i = map_viewport_x;
	int j = map_viewport_y;
	int k = map_viewport_x + map_viewport_w;
	int l = map_viewport_y + map_viewport_h;
	
	for(int ii = 0; ii < map_viewport_w / map.tile_size; ii++) {
		for(int jj = 0; jj < map_viewport_h / map.tile_size; jj++) {
			rect(buffer, i + ii * map.tile_size, j + jj * map.tile_size,
				i + ii * map.tile_size + map.tile_size, j + jj * map.tile_size + map.tile_size, makecol(50,50,50));
			int temp_tile_gfx = map.tile[(jj + map.scroll_y) * map.w + (ii + map.scroll_x)].tile_gfx;
			if(temp_tile_gfx >= 0)
				draw_sprite(buffer, (BITMAP*)the_datafile[temp_tile_gfx].dat , i + (map.scroll_x + ii * map.tile_size), j + (map.scroll_y + jj * map.tile_size));
		}
	}
	rect(buffer, i, j, k, l, makecol(255,255,255));
}

void c_gui::get_input(c_map map) {
	if(mouse_in_map_viewport) {
		int temp_index = (mouse_square_y + map.scroll_y) * map.w + (mouse_square_x + map.scroll_x);
		if(mouse_b & 1) {
			map.tile[temp_index].tile_gfx = gfx_tile000;
			map.tile[temp_index].layer = cur_layer;
		} 
		else if 
		(mouse_b & 2) {
			map.tile[temp_index].tile_gfx = -1;
			map.tile[temp_index].layer = cur_layer;
		} 
	}
}
		
void c_gui::set_map_viewport(int t_map_viewport_x, int t_map_viewport_y, int t_map_viewport_w, int t_map_viewport_h) {
	map_viewport_x = t_map_viewport_x;
	map_viewport_y = t_map_viewport_y;
	map_viewport_w = t_map_viewport_w;
	map_viewport_h = t_map_viewport_h;
}

void c_gui::update(c_map map) {
	if(map.w * map.tile_size <= map_viewport_w)
		map_viewport_w = map.w * map.tile_size;
	else
		map_viewport_w = default_map_viewport_w;
		
	if(map.h * map.tile_size <= map_viewport_h)
		map_viewport_h = map.h * map.tile_size;
	else
		map_viewport_h = default_map_viewport_h;
	
	if(mouse_x > map_viewport_x && mouse_y > map_viewport_y && mouse_x < map_viewport_x + map_viewport_w && mouse_y < map_viewport_y + map_viewport_h) {
		mouse_in_map_viewport = true;
		mouse_square_x = (mouse_x - map_viewport_x) / map.tile_size;
		mouse_square_y = (mouse_y - map_viewport_y) / map.tile_size;
	}
	else {
		mouse_in_map_viewport = false;
	}
}


global.h:
#ifndef _GLOBAL_H_
#define _GLOBAL_H

//#include <string>
#include <allegro.h>
#include <cstdlib>
#include <iostream>
#include "button.h"
#include "gui.h"
#include "map.h"

#endif


map.h:
#ifndef _MAP_H_
#define _MAP_H_
	
#include "global.h"
	
/*
 * tile_gfx - a number associated with which graphic to use for the tile
 * x, y - where the tile resides on the map
 * tile_type 
 */
struct c_tile {
 	public:
		int tile_gfx;
		int layer;
};

class c_map {
	public:
		int w, h;
		int scroll_x, scroll_y;
		int tile_size;
		c_tile* tile;

		c_map(int,int,int);
		void set_tile_size(int);
		void load_map(const char *filename);
		void save_map(const char *filename);

		void close_map();
};

#endif


map.cpp:
#include "global.h"

c_map::c_map(int t_width, int t_height, int t_tile_size) {
	w = t_width;
	h = t_height;
	if(t_tile_size < 1 || t_tile_size > 5)
		t_tile_size = 3;
	set_tile_size(t_tile_size);
	tile_size = t_tile_size * 8;
	tile = new c_tile[w*h];
	scroll_x = 0;
	scroll_y = 0;
	for(int i = 0; i < w*h; i++) {
		tile[i].tile_gfx = -1;
		tile[i].tile_type = T_NONSOLID;
	}
}

void c_map::set_tile_size(int new_size) {
	if(new_size >= 1 && new_size <= 5) {
		tile_size = 8;
		for(int i = 1; i < new_size; i++)
			tile_size = tile_size * 2;
	}
}

void c_map::close_map() {
	delete [] tile;
	tile = NULL;
}


And the button class isn't developed yet, just some stub code. This used to compile, I just can't figure out what I changed that broke it. :(

This post has been edited by jkh0208: 27 May 2009 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

#8 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 03:53 PM

Dev-c++ seems to be so buggy. I closed and reopened Dev-c++ and it gives me different errors. I also tried creating a new project and copied all the .h and .cpp files to the new project folder, and it gives me errors in my .h files' corresponding .cpp files like this:

In my gui.cpp I get an error "'c_gui' has not been declared"
c_gui::c_gui() {					 //Error occurs on this line
	map_viewport_x = default_map_viewport_x;
	map_viewport_y = default_map_viewport_y;
	map_viewport_w = default_map_viewport_w;
	map_viewport_h = default_map_viewport_h;
	cur_layer = 0;
}


But I have the class c_gui in my gui.h file:
class c_gui {
	public:
		int cur_layer;
		int map_viewport_x; //left bound of map viewport
		int map_viewport_y; //top bound of map viewport
		int map_viewport_w; //width of map viewport
		int map_viewport_h; //height of map viewport
		int mouse_square_x;
		int mouse_square_y;
		bool mouse_in_map_viewport;
		DATAFILE* the_datafile;

		c_gui();			   //Default constructor
		c_gui(DATAFILE*);
ect.

And I made sure my gui.cpp files includes the gui.h file, so I don't know what's going on. I just know I didn't have so many issues like this when I used M$VC++ Express, but I wanted a portable c++ environment to put on my flash drive and carry with me so I got dev-c++. Am I doing something wrong, or is dev-c++ really so glitchy that it changes it's error output even when the code hasn't changed?

This post has been edited by jkh0208: 27 May 2009 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

#9 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 04:02 PM

I haven't used dev in a while but it sounds like you are having environment issues that may or may not (hard to tell) be related to your code. Can you do a clean compile in VS Express?
Was This Post Helpful? 1
  • +
  • -

#10 jkh0208   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-May 09

Re: `c_gui' undeclared (first use this function)

Posted 27 May 2009 - 05:10 PM

View PostKYA, on 27 May, 2009 - 03:02 PM, said:

I haven't used dev in a while but it sounds like you are having environment issues that may or may not (hard to tell) be related to your code. Can you do a clean compile in VS Express?


Not yet. I actually just discovered code::blocks and it seems to be much, much better than dev-c++. I loaded my files into that and created a workspace, and it compiled and ran fine (after installing the allegro devpak). I don't get it, dev-c++ and code::blocks were using the same compiler by default, so they shouldn't have given different results. I'm glad I found code::blocks though. Thanks! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1