Inheritence Question

This is a discussion on Inheritence Question within the C++ Programming forums, part of the General Programming Boards category; Hey all, I have classes in my application, which inside themselves create pointers to other classes which came as part ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    Inheritence Question

    Hey all,

    I have classes in my application, which inside themselves create pointers to other classes which came as part of a library (Irrlicht in this case). Now I am new to OOP but I am sure this is just an inheritence issue. I am getting errors like this:

    ../include/config.h:32: ISO C++ forbids initialization of member `device'
    ../include/config.h:32: making `device' static
    ../include/config.h:32: invalid in-class initialization of static data member

    Which I assume leads to the errors like this:

    "main.cpp:184: `class Config' has no member named 'device' "

    ^ Even though the class does have a member named device. Now in this case this is the class where device is initalized:

    Code:
    class Config {
    public:
    // Variables
      IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(1800, 1100), 16, false, false, false, NULL);
      ISceneManager* smgr = device->getSceneManager();
      IVideoDriver* driver = device->getVideoDriver();
      core::stringw HelpText;
      video::E_DRIVER_TYPE driverType = EDT_OPENGL;
      int header;
      stringc str1, str2, str3, c1, c2, c3, c4;
      int header_lines, format_cols, driverType_int;
    
    // Functions
    	      Config();
    	     ~Config();
       void ReadXML(void);
       void writeConfigFile();
       void updatePref();
    };
    and this is how I call it in main.cpp: config.device->run()

    Now device is a member of the Irrlicht library, have I forgotten to inherit this library properly?
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,068
    You don't initialize variables in a class definition, that's what the constructor is for. If you want every instance of the class to have the exact same value in those initialized variables, then you can declare them as static and initialize them outside of the class definition. Be aware, doing so with those pointers will lead to every instance pointing to the same device. You likely want to initialize those in your constructor. You should read up on OOP before you jump into it.
    Last edited by SlyMaelstrom; 08-15-2006 at 08:13 AM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    208
    I have been reading up on it, I am just applying the knowledge now. Ok, so if I initalize them in the contructor they are accessible outside correct? Also is it neccessary to make my base class a child of the Irrlicht base class to use those pointers within mine? My instincts tell me no.
    Last edited by kas2002; 08-15-2006 at 08:30 AM.
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208
    I got it to work, thank you for you lesson on OOP, I am sure it will serve me well
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21