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?

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.

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();

No suggestions? I'm totally at a loss here :(

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

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

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

where did you initialize the 'mainDisplay' object?

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();

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.

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.

Do you mind posting the actual error text? It may provide more hints.

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()
	{
	}
};

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".

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.