This skin was created by Rocky of the IF Skin Zone


 

 [c++] Oop Help, Thats right, Im back
Daniel
Posted: Dec 24 2007, 04:57 AM


Gamehawks Loyal Follower


Group: Members
Posts: 387
Member No.: 45
Joined: 16-January 06



Hows it going people? I'm hanging up my PHP Enviroment for a while and having another play with C++ and Allegro. Ran into some problems tho.

I'm having an OOP problem. I'm using Dev-C++ and trying to initialize allegro in a very basic. BUT, this question doesn't require an allegro knowledge. I have 3 files (main.cpp, Device.h, Device.cpp). Now so far I have created the project, wrote the main.cpp code, then added the other two files and wrote their code. Here is the error I'm getting:

QUOTE

Line 10: 'gfxDevice' is not a known namespace or class


And here is my code:
main.cpp:
CODE

#include <allegro.h>
#include "Device.h"

using namespace std;

Device gfxDevice;

int main() {
   
   gfxDevice::initialize(1024, 800);

while (!key[KEY_ESC]) {
 /* put your code here */
}

gfxDevice::deinitialize();

return 0;

}
END_OF_MAIN()


Device.h:
CODE
//Device.h

#ifndef DEVICE_H
#define DEVICE_H

#include <allegro.h>

class Device {

public:
      Device();
      ~Device();

      // These two functions intialize Allegro
      void initialize(int res_x, int res_y);
      void deinitialize();
     
private:

      int depth();
      int res();

};

#endif



Device.cpp:
CODE
//Device.cpp
#include "Device.h"

Device::Device() {
   
}

Device::~Device() {
                 
}

void Device::initialize(int res_x, int res_y) {
           
   allegro_init();
   
   Device::depth();
   
   Device::res(res_x, res_y);

install_timer();
install_keyboard();
install_mouse();
                   
}

void Device::deinitialize() {

  clear_keybuf();
   
}

int Device::depth() {
   
   depth = desktop_color_depth();

if (depth == 0) {
       
       depth = 32;
       
   }

set_color_depth(depth);
 
   return 1;
   
}

int Device::res(int res_x, int res_y) {
   
   res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, res_x, res_y, 0, 0);

if (res != 0) {
           
 allegro_message(allegro_error);

       exit(-1);
       
}
   
}



What am I missing? Did I not do something right? or is it my code?

Dan


--------------------
1 pwn @ll y0u l0s3rs! G0 j4ck 0ff 1n4 a cup!
Top
Neken
Posted: Dec 26 2007, 03:39 PM


DirectX Guru


Group: Global Moderators
Posts: 515
Member No.: 11
Joined: 24-September 05



gfxDevice.initialize(1024, 800); not :: tongue.gif

:: is the scope operator


--------------------
Top


Topic Options



Hosted for free by InvisionFree (Terms of Use: Updated 7/7/05) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Page creation time: 0.4041 seconds | Archive