Inherited method not called?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Inherited method not called?

  1. #1
    Join Date
    Dec 2010
    Posts
    646

    Inherited method not called?

    OgreWidget.h
    Code:
     
    #ifndef __OGREWIDGET_H__
    #define __OGREWIDGET_H__
     
    #include <OGRE/Ogre.h>
    #include <QGLWidget>
    //#include <QX11Info>
     
    class OgreWidget : public QGLWidget
    {
      //Q_OBJECT;
     
     public:
      OgreWidget( QWidget *parent=0 ):
        QGLWidget( parent ),
        mOgreWindow(NULL)
        {
          init( "./plugins_d.cfg", "./ogre.cfg", "./ogre.log" );
          createCamera();
          createViewports();
          createScene();
        }
     
      virtual ~OgreWidget()
        {
          mOgreRoot->shutdown();
          delete mOgreRoot;
          destroy();
        }
     
     protected:
      virtual void initializeGL();
      virtual void resizeGL( int, int );
      virtual void paintGL();
      virtual void initNavMesh() { }
      virtual void createCamera() { }
      virtual void createViewports() { }
      virtual void createScene() { }
     
      void init( std::string, std::string, std::string );
     
      virtual Ogre::RenderSystem* chooseRenderer( const Ogre::RenderSystemList&  );
     
      Ogre::Root *mOgreRoot;
      Ogre::RenderWindow *mOgreWindow;
      Ogre::Camera *mCamera;
      Ogre::Viewport *mViewport;
      Ogre::SceneManager *mSceneMgr;
    };
     
    #endif
    myGLWidget.h
    Code:
    #ifndef MYGLWIDGET_H
    #define	MYGLWIDGET_H
    
    
     #define _DEBUG 1
    
    #include <d3d9.h>
    #include "OgreWidget.h"
    //#include "ogrerecast/Samples/include/BaseApplication.h"
    
    
    
    using namespace Ogre;
     
    class myGLWidget :  public OgreWidget {
    public:
    #ifdef QWIDGET_H
        myGLWidget( QWidget *parent = 0, Qt::WindowFlags flags = 0);
    #else
        myGLWidget();
    #endif
        
        virtual ~myGLWidget(); 
        
        //virtual void initEffects();
        virtual void initNavMesh(); 
        
        virtual void paintEvent (QPaintEvent *e); 
        
        virtual void resizeGL( int nWidth, int nHeight );
        
        /*void createCamera(void); */
        
        //-------------------------------------------------------------------------------------
        /*void createViewports(void); */
     
        //-------------------------------------------------------------------------------------
        virtual void createScene(); 
    };
    
     
    #endif	/* MYGLWIDGET_H */
    Code:
    /* 
     * File:   myDX9Widget.cpp
     * Author: Jacky
     * 
     * Created on 2014年04月28日 星期一, 下午6:34
     */
    
     
    #include <iostream>
    #include "./myGLWidget.h"
    #include "./DotSceneLoader.h"
    
    using namespace Ogre;
    using namespace std;
    
    #ifdef QWIDGET_H
        myGLWidget::myGLWidget( QWidget* parent, Qt::WindowFlags flags)
            : OgreWidget ( parent )
        {  
             
        }
    #else
        myGLWidget::myGLWidget() 
        {
            
        }
    #endif
        
        myGLWidget::~myGLWidget() {
             
        } 
        
        void myGLWidget::initNavMesh() {
            
        } 
         
        void myGLWidget::paintEvent(QPaintEvent* e) {
            //assert( mWindow );
            if (mOgreWindow) {
                mOgreRoot->renderOneFrame();
            }
            
        }
        
        void myGLWidget::resizeGL(int nWidth, int nHeight) {
        //            setAspect(width() / (float) height());
            //assert( mWindow );
            if (mOgreWindow) {
                mOgreWindow->reposition( this->pos().x(), 
                                    this->pos().y() );    
                mOgreWindow->resize( nWidth, nHeight );
                paintEvent(0);
            }
        }
        
        // 1
       /* void myDX9Widget::createCamera(void)
        {
            OutputDebugStringA("createCamera");
        }
    
        // 2
        //-------------------------------------------------------------------------------------
       void myDX9Widget::createViewports(void)
        {
        }*/
    
        // 3
        //-------------------------------------------------------------------------------------
        void myGLWidget::createScene()
        {
             
            
            DotSceneLoader* dotSceneLoader = new DotSceneLoader(); 
            dotSceneLoader->parseDotScene("Warehouse.scene", "Essential", mSceneMgr);        
            //OutputDebugStringA("Finished");
            OutputDebugStringA("createScene");
            
            delete dotSceneLoader;
            
        }




    The inherited method called createScene is not called. No ideas why?
    Last edited by lucky6969b; May 6th, 2014 at 11:24 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,358

    Re: Inherited method not called?

    Read Scott Meyers' article as to why you should Never Call Virtual Functions during Construction or Destruction. Notice that createScene is a virtual function that is called in the OgreWidget constructor.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center