Thread: More Class Help

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

    More Class Help

    Hello Again, I was hoping to get somemore class help, though this may fall under the inheritance tab as well.

    I have two classes Class Config, and class Gui (which is a derived class of Config)
    Now to access a public variable in Config, must I reference config or can I just treat it as though it were a public variable of the Gui Class. For example, device is a public pointer in the Config class. Within my Gui constructor I reference it, please let me know if this is being done properly because when I try and call a function (even with everything in the function being commented out) I get a segmentation fault and I just cannot locate where it is occuring.

    Code:
    Gui::Gui(){
    
      env = device->getGUIEnvironment();
      prefenv = device->getGUIEnvironment();
      if(!env)
    {
        printf("oopsie, env is bad.\n");
        return;
    }
    if(!prefenv)
    {
        printf("oopsie, prefenv is bad.\n");
        return;
    }
      
    }
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Shure any public or protected member variable can be accessed by your derived class.
    We would have to see some code to tell you exactly why your Gui constructor segfaults. ( if you get that far as to a segfault your program has to be syntactically correct ).
    But keep in mind that in the constructor of Gui only the members of Config that are initialized in Config's constructor ( default constructor in this case ) are valid.
    Kurt
    Last edited by ZuK; 08-16-2006 at 08:43 AM.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    208
    Ok, well I can post some code, but it is not actually my constructor which is seg faulting it is a call to a method within the GUI class. In an attempt to find the error I have commented out everything in the fucntion who's call is causing the seg. fault. and it is still occuring. I will post both of my classes here however.

    Code:
    class Config {
    public:
    // Variables
      core::stringw HelpText;
      int header;
      stringc str1, str2, str3, c1, c2, c3, c4;
      int header_lines, format_cols, driverType_int;
      IrrlichtDevice *device;
      ISceneManager* smgr;
      IVideoDriver* driver;
      video::E_DRIVER_TYPE driverType;
    
    // Functions
    	      Config();
    	     ~Config();
       void ReadXML(void);
       void writeConfigFile();
       void updatePref();
    };
    Code:
    class Gui : public Config  {
    public:
    // Variables
      IGUIStaticText* fpstext;
      IGUIStaticText* timetext;
      IGUIStaticText* frametext;
      IGUIEnvironment* env;
      IGUIEnvironment* prefenv;
        
         	Gui();
    	   ~Gui();
     void createGUI();
     void showPref();
     void showAboutText();
     
    };
    This is the function which is causing the seg. fault.

    Code:
    void Gui::createGUI()
    { /*printf("Creating GUI..\n");
      //IGUIToolBar* bar = env->addToolBar();
      printf("Toolbar Created..\n");
      //env->addStaticText(L"Constant Path: ", core::rect<s32>(8,10,90,25), false);
      //IGUIEditBox* namebox = env->addEditBox(L"Test/X", core::rect<s32>(100,8,240,25), true, bar, 901);
      printf("Const. Path Box Created..\n");
      //env->addStaticText(L"Start#:", core::rect<s32>(250,10,300,25), false);
      //IGUIEditBox* range1box = env->addEditBox(L"1", core::rect<s32>(310,8,350,25), true, bar, 902);
      printf("Range1 Box Created..\n");
      //env->addStaticText(L"End#: ", core::rect<s32>(360,10,410,25), false);
      //IGUIEditBox* range2box = env->addEditBox(L"1", core::rect<s32>(420,8,470,25), true, bar, 903);
      printf("Range2 Box Created..\n");
      //IGUICheckBox* sphere_check_box = env->addCheckBox (true,core::rect<s32>(490,8,510,25) , bar, 400, L"Spheres");
      //IGUICheckBox* box_check_box = env->addCheckBox (false,core::rect<s32>(530,8,550,25), bar, 400, L"Boxes");
      printf("Check Boxes Created..\n");
      //IGUIButton* launchbutton = env->addButton(core::rect<s32>(570,8,600,25), bar, 1101, L"Launch");
      printf("Launch Button Created..\n");
      //fpstext = env->addStaticText(L"", core::rect<s32>(850,8,900,25), true);
      //timetext = env->addStaticText(L"", core::rect<s32>(910,8,1010,25), true);
      //frametext = env->addStaticText(L"", core::rect<s32>(1020,8,1150,25), true);
      printf("Static Text's Created..\n");
    
      //IGUIButton* helpbutton = env->addButton(core::rect<s32>(1750,8,1790,25), bar, 1102, L"Help");
      //IGUIButton* prefbutton = env->addButton(core::rect<s32>(1650,8,1740,25), bar, 1103, L"Preferences");
      printf("Help and Pref. Buttons Created..\n");
    
    
    
      //IGUISkin* skin = env->getSkin();
      printf("Got Skin..\n");
      //IGUIFont* font = env->getFont("../include/fonthaettenschweiler.bmp");
      printf("Got Font..\n");
    
        //skin->setFont(font);
        printf("Font Set..\nBeginning Alpha Loop\n");
    
      	//for (s32 k=0; k<gui::EGDC_COUNT ; k++)
    	//{
     	//	SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)k);
    	//	col.setAlpha(255);
    	//	env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)k, col);
    	//}
      printf("Alpha Loop Finshed..\n");
    
    
      stringw capstr = L"Visualization";
      //device->setWindowCaption(capstr.c_str());
      printf("Window Caption Set..\nGUI Finished\n"); */
    
    }
    and it is being called like follows in main.cpp

    Code:
    Gui interface;
    
    interface.createGUI();
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208
    I was doing some thinking, and I think I may have figured this out. I have a question first though, when I create an instance of Gui I reconstruct config as well correct? In my main function I am using an instance of Config do control my devices and the like, and I think, if I am correct, when I call an instance of Gui I am pointing to a different device then I am using. Example below in psuedo.....

    Using the classes above...
    Code:
    Config config;
    Gui interface;
    
    config.device->run()
    interface->createGUI();
    Now the variable in create GUI called 'env', actually points to 'device' in config during intialization. Would these two instances point to the same device?? Because if not then I think I found the fault
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Since Gui inherits Config there would be two devices in your case ( unless device is a static member of Config ).
    Kurt

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    208
    Well I got rid of the instance of config in my Main.cpp, however I still get this fault. Which strikes me as odd because I figured this to be the answer.
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 11:36 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM