C + + constructor and instantiation learning! __jquery

Source: Internet
Author: User

In the Page75 of Ogre Learning, he encountered a problem, because he read the English document, his understanding of the author is wrong,

(This is the reason of English, I still want to read more English documents), because the understanding of mistakes, they put a low-level mistake, unexpectedly

When a class is defined (it has two constructors, one with one argument and the other with that argument), instantiate the class with a

Parameters to instantiate, oh, always think of their own C + + can, today know that they have to learn the basis of C + +.

Debugging code for a long time, finally achieve the desired effect, the source code down, notes as detailed as possible, have the time to read.

Platform Win32:console applications: Code: #include   "Ogre/exampleapplication.h"    #include   " ExampleFrameListener.h "   #include  " OIS.h "   #include  <iostream>       class example27framelistener :p ublic ogre::framelistener    {   Public:           example27framelistener (Ogre::scenenode* node, Renderwindow * win)        {            //defines a pointer to a   render window: Win            _node  = node;               size_t  windowhnd =  0;               std::stringstream windowHndStr;               win->getcustomattriBute ("window", &AMP;WINDOWHND);            //Converts window handles to strings             windowHndStr <<windowHnd;            //Creates a parameter list for OIS, inserts the window handle into the list             ois::P aramlist pl;                         pl.insert (Std::make_pair (std::string ("window"), Windowhndstr.str ());            //Create input system and copy it to _man             _man = ois::inputmanager::createinputsystem (PL);            //Use OIS keyboard to obtain user input             _key = static_cast<OIS::Keyboard*> (_man->createinputobject (    &NBSp;           ois::oiskeyboard,false));            }              bool  framestarted (const ogre::frameevent &evt)        {           //capture user Input             _key->capture ();            if  (_key->iskeydown (ois :: kc_ ESCAPE)            {                //If the user presses esc  stop render frame exit                 return false;            }             _node ->translate (Ogre::vector3 (10,0,0) *evt.timesincelastframe);               return true;       &nbsp}           example27framelistener ( Ogre::scenenode node)        {               FrameListener = NULL;       &nbsp}        ~example27framelistener ()        {           //Destroy input objects            _man->destroyinputobject (_key);            //Destroy input system             ois::inputmanager::d Estroyinputsystem (_man);       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP; (framelistener)            {                delete FrameListener;           &nbsp}        }       Private:        Ogre::SceneNode* _node;        Ogre::FrameListener* FrameListener;        OIS::InputManager* _man;        OIS::Keyboard* _key;   };       class example :p ublic exampleapplication    {   public &NBSP:        void createscene ()//just realize virtual  function createscene  on it.        {            ogre::P Lane plaNE (vector3::unit_y,-10);               ogre::meshmanager::getsingleton (). Createplane ("Plane",                 Resourcegroupmanager::D efault_resource_group_name,plane,            &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;1500,1500,200,200,TRUE,&NBSP;1,5,5,VECTOR3::UNIT_Z);                         Ogre::Entity* ent =                  mscenemgr->createentity ("Lightplaneentity", "plane");                   //   attation please; must add this dialog;            mscenemgr->getrootscenenodE ()->createchildscenenode ()->attachobject (ENT);               ent->setmaterialname ("examples/ Beachstones ");               Ogre::Light* light =  Mscenemgr->createlight ("Light1");            light->settype (ogre::light::lt_directional);            light->setdirection (Ogre::vector3 (1,-1,0));                  ogre::scenenode *  node = mscenemgr->createscenenode ("Node1");            mscenemgr->getrootscenenode ()->addChild (node );               Ogre::Entity* Sinbad =  Mscenemgr->createentity ("Sinbad", "Sinbad.mesh");  &nbSp            _SinbadNode = node-> Createchildscenenode ("Sinbadnode");            _sinbadnode->setscale (3.0f,3.0f,3.0f);            _sinbadnode->setposition (Ogre::Vector3 (  0.0f, 4.0f, 0.0f));            _sinbadnode->attachobject (Sinbad);            mscenemgr->setshadowtechnique (SHADOWTYPE_ stencil_additive);           }        //  overrode  the createCamera  ()  function                  void createcamera ()        {            mCamera = mSceneMgr->Createcamera ("MyCamera1");            mcamera->setposition (0,100,200);            mcamera->lookat (0,0,0);            mcamera->setnearclipdistance (5);        }           void  Createframelistener ( )        {            example27framelistener* framelistener= new example27framelistener (_SinbadNode , Mwindow);/is here, instantiated            mRoot-> according to the constructor defined in the class Addframelistener (Framelistener);       &nbsp          private:         Ogre::SceneNode* _SinbadNode;         };      //  listoner framwork       int main (void)    {      & nbsp;   example app;        app.go ();        return 0;   }   

STL Small Knowledge:

Application of Make_pair () function

Template<class, class second> inline

Pair<first, second> make_pair (const first& _x, const second& _y)

Make_pair is the combination of 2 data into one data, when the need for such requirements can be used pair, such as the STL map is the key and value together to save. Another application is that when a function needs to return 2 data, it can choose pair. The implementation of pair is a struct, the main two member variable is first second because it is using struct is not class, so you can directly use the pair member variable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.