0

I have no idea what is going on here, first, the code:

#pragma once

#include <stdio.h>
//#include <stdafx.h>
#include <allegro5/allegro.h>
//#include <allegro_image.h>

class DisplayController
{
public:

    int bitmapx;
	int bitmapy;

   // ALLEGRO_DISPLAY display;
	ALLEGRO_BITMAP *crosshairs; 
	ALLEGRO_EVENT ev;
	ALLEGRO_EVENT_QUEUE *event_queue;

	void display()
	{
						this->event_queue = al_create_event_queue();
						al_register_event_source(event_queue, al_get_mouse_event_source());
						al_wait_for_event(event_queue, &ev);
						
		        	    this->crosshairs = al_load_bitmap("crosshairs.bmp");
		                if(!crosshairs)
						{
							fprintf(stderr,"Bitmap is null!");
							al_rest(2.0);
						}
               
				if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY)
				{
                   bitmapx = (ev.mouse.x -60);
				   bitmapy = (ev.mouse.y -60);
		           al_draw_bitmap(crosshairs,bitmapx,bitmapy,0);
		           al_flip_display();
				}

		       //al_rest(2.0);
	}

	bool mouseClicked()
	{
		if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	void DisplayController()
	{
		//this->display = new ALLEGRO_DISPLAY;
		this->bitmapx = 0;
		this->bitmapy = 0;
	}
	void ~DisplayController()
	{
	}
};

So when I call that display function from main (objectName->display()), I get the private member error message, even though I've explicity stated that the function is public about 6 lines above! There's nothing in that class declared as private so why does the compiler seem to think it's private?

6
Contributors
15
Replies
16
Views
5 Years
Discussion Span
Last Post by kutuup
0

Some more code would be helpful, like the relevant part of your main(). The only errors I see as far as class setup goes are that your constructor and destructor have return types, which isn't allowed.

0

Some more code would be helpful, like the relevant part of your main(). The only errors I see as far as class setup goes are that your constructor and destructor have return types, which isn't allowed.

Here is the main function:

int main(int argc, char **argv)
{

   if(initialize() == false)
   {
   fprintf(stderr, "initialization failed!");
   al_rest(1.0);
   return 0;
   }

   al_rest(2.0);


	while(true)
	{
		al_clear_to_color(al_map_rgb(0,0,0));
		mainDisplay->display();
		al_flip_display();
		if(mainDisplay->ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
					break;
		}
	}
 
   al_destroy_display(display);
 
   return 0;
}

I've removed the return types on the constructor and destructor too, they weren't throwing up any errors which is odd :S

The error points to the line: mainDisplay->display();

0

Maybe something to do with creating the function with no prototype? Normally you would separate class into a .h and .cpp file. Not sure though, maybe you don't need prototypes in classes

Edited by Akill10: n/a

0

Maybe something to do with creating the function with no prototype? Normally you would separate class into a .h and .cpp file. Not sure though, maybe you don't need prototypes in classes

I've always declared classes this way before and had no problems :S

0

Are the ALLEGRO_BITMAP, ALLEGRO_EVENT, ALLEGRO_EVENT_QUEUE identifiers macros, or just normal types?

Edited by chrjs: n/a

0

where did you initialize the 'mainDisplay' object?

Outside the main function, at the top of the file (the code I pasted is just the main function), it's a global variable, is that bad?

I declared it thusly

DisplayController * mainDisplay = new DisplayController();
0

Are the ALLEGRO_BITMAP, ALLEGRO_EVENT, ALLEGRO_EVENT_QUEUE identifiers macros, or just normal types?

Sorry, I'm not sure what you mean, they are classes declared in the Allegro library I presume. Either that or they are normal types, not sure what a macro is.

0

You could try making the main function a friend of the DisplayController class, although that is more of a work-around than an actually solution.

0

Error 1 error C2248: 'DisplayController::display' : cannot access private member declared in class 'DisplayController' c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 93

That's the text the error gives.

There are other errors too:

Error 2 error C2064: term does not evaluate to a function taking 0 arguments c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 93

Error 3 error C2039: 'ev' : is not a member of 'DisplayController' c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 95

Error 4 error C2228: left of '.type' must have class/struct/union c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 95


The second error also confuses me since Display() most definitely is a member function of DisplayController:

class DisplayController
{
public:

    int bitmapx;
	int bitmapy;

   // ALLEGRO_DISPLAY display;
	ALLEGRO_BITMAP *crosshairs; 
	ALLEGRO_EVENT ev;
	ALLEGRO_EVENT_QUEUE *event_queue;

	void display()
	{
						this->event_queue = al_create_event_queue();
						al_register_event_source(event_queue, al_get_mouse_event_source());
						al_wait_for_event(event_queue, &ev);
						
		        	    this->crosshairs = al_load_bitmap("crosshairs.bmp");
		                if(!crosshairs)
						{
							fprintf(stderr,"Bitmap is null!");
							al_rest(2.0);
						}
               
				if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY)
				{
                   bitmapx = (ev.mouse.x -60);
				   bitmapy = (ev.mouse.y -60);
		           al_draw_bitmap(crosshairs,bitmapx,bitmapy,0);
		           al_flip_display();
				}

		       //al_rest(2.0);
	}

	bool mouseClicked()
	{
		if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	DisplayController()
	{
		//this->display = new ALLEGRO_DISPLAY;
		this->bitmapx = 0;
		this->bitmapy = 0;
	}
	~DisplayController()
	{
	}
};
0

Error 1 error C2248: 'DisplayController::display' : cannot access private member declared in class 'DisplayController' c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 93

That's the text the error gives.

There are other errors too:

Error 2 error C2064: term does not evaluate to a function taking 0 arguments c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 93

Error 3 error C2039: 'ev' : is not a member of 'DisplayController' c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 95

Sorry, typo, that should read "display()

Error 4 error C2228: left of '.type' must have class/struct/union c:\users\james\documents\visual studio 2008\projects\red ice 1.0\red ice 1.0\red ice 1.0.cpp 95


The second error also confuses me since Display() most definitely is a member function of DisplayController:

class DisplayController
{
public:

    int bitmapx;
	int bitmapy;

   // ALLEGRO_DISPLAY display;
	ALLEGRO_BITMAP *crosshairs; 
	ALLEGRO_EVENT ev;
	ALLEGRO_EVENT_QUEUE *event_queue;

	void display()
	{
						this->event_queue = al_create_event_queue();
						al_register_event_source(event_queue, al_get_mouse_event_source());
						al_wait_for_event(event_queue, &ev);
						
		        	    this->crosshairs = al_load_bitmap("crosshairs.bmp");
		                if(!crosshairs)
						{
							fprintf(stderr,"Bitmap is null!");
							al_rest(2.0);
						}
               
				if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY)
				{
                   bitmapx = (ev.mouse.x -60);
				   bitmapy = (ev.mouse.y -60);
		           al_draw_bitmap(crosshairs,bitmapx,bitmapy,0);
		           al_flip_display();
				}

		       //al_rest(2.0);
	}

	bool mouseClicked()
	{
		if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	DisplayController()
	{
		//this->display = new ALLEGRO_DISPLAY;
		this->bitmapx = 0;
		this->bitmapy = 0;
	}
	~DisplayController()
	{
	}
};

Sorry, typo, that should read "display() most definitely is a member function of DisplayController".

0

Still no solution my end. Whatever I try I still get this error, could it be a Visual Studio bug?

0

Scratch that, found the problem, for some reason I had a duplicate displaycontroller.h file, one of them blank, for some reason it was reading the blank one!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.