Warum der Fehler ?
-
Hallo,
ich habe nur eine kurze Frage, mein Code sieht so aus:#include <irrlicht.h> using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; #pragma comment(lib, "Irrlicht.lib") class Init{ public: void ini() { IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 16, true, false, false, 0); device->setWindowCaption(L"Mindhunter 2k"); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); guienv->addStaticText(L"This ist a V. 006 Beta from Mindhunters 2k", rect<int>(10,10,200,22), true); //Figur Laden IAnimatedMesh* mesh = smgr->getMesh("Objekte/person.3ds"); IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh ); //Map Laden device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3"); scene::IAnimatedMesh* map = smgr->getMesh("20kdm2.bsp"); scene::ISceneNode* mapNode = 0; if (map) mapNode = smgr->addOctTreeSceneNode(map->getMesh(0)); if (node) { node->setMaterialFlag(EMF_LIGHTING, false); //node->setFrameLoop(0, 310); //node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); } //Camera erstellen //smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); smgr->addCameraSceneNodeFPS(); // Zeichnen while(device->run()) { /* Anything can be drawn between a beginScene() and an endScene() call. The beginScene clears the screen with a color and also the depth buffer if wanted. Then we let the Scene Manager and the GUI Environment draw their content. With the endScene() call everything is presented on the screen. */ driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); guienv->drawAll(); driver->endScene(); } // Device Leeren device->drop(); } }; int main() { Init::ini(); return 0; }
und ich bekomme diesen Fehler:
--------------------Konfiguration: HelloWorld - Win32 Debug--------------------
Kompilierung läuft...
main.cpp
C:\irrlicht\irrlicht-0.14.0\examples\01.HelloWorld\main.cpp(85) : error C2352: 'Init::ini' : Unzulaessiger Aufruf einer nichtstatischen Member-Funktion
C:\irrlicht\irrlicht-0.14.0\examples\01.HelloWorld\main.cpp(17) : Siehe Deklaration von 'ini'
Fehler beim Ausführen von cl.exe.HelloWorld.exe - 1 Fehler, 0 Warnung(en)
Und nun frage ich euch: "Warum ? ;-)"
Danke im Vorraus
-
Du benötigst ein Objekt vom Typ "Init", um dessen Memberfunktionen aufzurufen:
int main() { Init i; i.ini(); }
(alternativ könntest du die Methode als "static void ini()" definieren, dann klappt der Code so)
PS: Wozu brauchst du überhaupt die Klasse? Nimm lieber eine globale init()-Funktion, in die du den ganzen Kram reinpackst.