miedziaq Temat założony przez niniejszego użytkownika  | 
[C++] Dziedziczenie implementacji funkcji z klasy podstawowej » 2015-01-04 14:39:46 Witam W klasie bazowej mam utworzone metody i właściwości, wszystkie wraz z ich implementacją chciałbym dziedziczyć do klasy pochodnej. Jednak działa to jedynie gdy implementacje metody zapisze bezposrednio wewnątrz klasy. Implementacje chciałbym zapisac w pliku {nazwaklasy.cpp} odnosząc się poprzez operator :: Nie potrafię sobie poradzic z tym problemem. plik: object.hpp #ifndef OBJECT_HPP #define OBJECT_HPP
  #include<Windows.h> #include<d3dx9.h> #include<d3d9.h> #include"engine.hpp"
  class CObject { public:          void MoveX() { x += movex; };     void MoveY() { y += movey; };     void NextFrame();     void IncreaseAnimCount() { animcount++; };          int const GetX() { return x; };     int const GetY() { return y; };     int const GetWidth() { return width; };     int const GetHeight() { return height; };     int const GetCurFrame() { return curframe; };     int const GetLastFrame() { return lastframe; };     int const GetAnimDelay() { return animdelay; };     int const GetAnimCount() { return animcount; };     int const GetScaleX() { return scalex; };     int const GetScaleY() { return scaley; };     int const GetRotation() { return rotation; };     int const GetRotateRate() { return rotaterate; };     virtual D3DXVECTOR3 GetPosition() = 0;     LPDIRECT3DTEXTURE9 const GetObjectTexture() { return objecttexture; };          void SetX( int xpos ) { x = xpos; };     void SetY( int ypos ) { y = ypos; };     void SetAnimDelay( int animdelayval ) { animdelay = animdelayval; };     void SetScaleX( int scalexval ) { scalex = scalexval; };     void SetMoveX( int movexval ) { movex = movexval; };     void SetMoveY( int moveyval ) { movey = moveyval; };     void SetScaleY( int scaleyval ) { scaley = scaleyval; };     void SetRotation( int rotationval ) { rotation = rotationval; };     void SetRotateRate( int rotaterateval ) { rotaterate = rotaterateval; };     void SetFileName( LPCTSTR filenameval ) { filename = filenameval; };     void SetObjectTexture( int r, int g, int b );      protected:     int x, y;     int width, height;     int movex, movey;     int curframe, lastframe;     int animdelay, animcount;     int scalex, scaley;     int rotation, rotaterate;     LPCTSTR filename;     LPDIRECT3DTEXTURE9 objecttexture; };
  #endif
  Plik object.cpp #include "object.hpp" #include <d3d9.h> #include <d3dx9.h> #include "engine.hpp"
  void CObject::SetObjectTexture( int r, int g, int b ) {     objecttexture = LoadTexture( filename, D3DCOLOR_XRGB( r, g, b ) ); } plik noose.hpp  klasa dziedziczaca #ifndef NOOSE_HPP #define NOOSE_HPP #include "object.hpp"
  class CNoose     : public CObject { public:     CNoose();     CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval );     CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval, int scalexval, int scaleyval );     CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval, int scalexval, int scaleyval, int rotationval, int rotaterateval );     ~CNoose() { if( objecttexture != NULL ) objecttexture->Release(); };          void NextFrame();     D3DXVECTOR3 GetPosition();      };
  #endif plik noose.cpp #include "object.hpp" #include "noose.hpp"
  CNoose::CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval ) {     filename = spritename;     x = xpos;     y = ypos;     movex = movexval;     movey = moveyval;     height = heightval;     width = widthval;     lastframe = 11;           }
  CNoose::CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval, int scalexval, int scaleyval ) {     filename = spritename;     x = xpos;     y = ypos;     movex = movexval;     movey = moveyval;     scalex = scalexval;     scaley = scaleyval; }
  CNoose::CNoose( LPCTSTR spritename, int xpos, int ypos, int heightval, int widthval, int movexval, int moveyval, int scalexval, int scaleyval, int rotationval, int rotaterateval ) {     filename = spritename;     x = xpos;     y = ypos;     movex = movexval;     movey = moveyval;     scalex = scalexval;     scaley = scaleyval;     rotation = rotationval;     rotaterate = rotaterateval; }
 
 
 
  void CNoose::NextFrame() {     if( curframe <= lastframe )          curframe++;     else     {         curframe = 1;     } }
 
 
 
 
  D3DXVECTOR3 CNoose::GetPosition() {     D3DXVECTOR3 position(( float ) x,( float ) y, 0 );     return position; }
  Funkcje implementowane w klasie bazowej działają dopóki nie muszą zmieniać którejś z wlasciwosci i nie sa zaimplementowane wewnatrz klasy w pliku object.hpp w Main wywolywane sa CNoose rope2( "rope.png", 500, 500, 116, 256, 6, 6 ); rope2.SetObjectTexture( 255, 0, 254 ); rope2.GetObjectTexture(),
  Error	2	error LNK2019: unresolved external symbol "public: void __thiscall CObject::SetObjectTexture(int,int,int)" (?SetObjectTexture@CObject@@QAEXHHH@Z) referenced in function "int __cdecl Game_Init(struct HWND__ *)" (?Game_Init@@YAHPAUHWND__@@@Z)	D:\Documents and Settings\Dominik\Moje dokumenty\Visual Studio 2010\Projects\Hangman_2D\game.obj
  Czy ktos moglby mi pomoc z tym problemem? [EDIT] Problem rozwiązany, visual nie rozpoznawał plików .hpp utworzonych ręcznie poza środowiskiem [/EDIT]  |