Inheritance question

Started by
17 comments, last by Deyja 18 years, 9 months ago

Base class object

//===============================================================================================////	File :xObject.h////	Date Created  : 6/30/2005//	Date Modified : 7/13/2005////===============================================================================================////	The base class for all objects////===============================================================================================#ifndef _XOBJECT_H_#define _XOBJECT_H_#include "Impulse.h"namespace Impulse{	namespace Base	{		class xObject		{		/* PRIVATE MEMBER VARIABLES */		private:			int			m_iUniqueID;			std::string m_strName;					/* PROTECTED MEMBER VARIABLES */		protected:			bool m_bDisposed;		/* PUBLIC METHODS */		public:			/* CONSTRUCTORS */			xObject(void);			xObject(std::string name);			/* DESTRUCTOR */			~xObject(void);			//Calls the public dispose method			void Dispose(void);			//Gets the unique ID of the object			int UniqueID(void);			//Gets the name of the object			std::string Name(void);		/* PROTECTED METHODS */		protected:			//Inheritable method, release any allocated memory			virtual void Dispose(bool disposing);		};	//End class xObject	}	//End namespace Base}	//End namespace Impulse#endif


Scene Node class in same namespace, I can use the methods here
//===============================================================================================////	File : xSceneNode.h////	Date Created  : 7/01/2005//	Date Modified : 7/13/2005////===============================================================================================////	This is the base class for all things that are renderable to the screen.////===============================================================================================#ifndef _XSCENENODE_H_#define _XSCENENODE_H_#include "Impulse.h"namespace Impulse{	namespace Base	{		//class xSceneNode inherits from xObject		class xSceneNode : public Impulse::Base::xObject		{		/* PRIVATE MEMBER VARIABLES */		private:			IDirect3DDevice9 *m_pD3DDevice;			D3DXVECTOR3		  m_v3Translation, 							  m_v3Rotation, 							  m_v3Origin, 							  m_v3Scale;			D3DXMATRIX		  m_matWorld, 				              m_matTranslation, 							  m_matRotation, 							  m_matScale;			bool			  bIsVisible;		/* PUBLIC METHODS */		public:			/* CONSTRUCTORS */			xSceneNode(IDirect3DDevice9 *pD3DDevice);			xSceneNode(IDirect3DDevice9 *pD3DDevice, std::string name);			//Gets the nodes render device			IDirect3DDevice9 *GetDevice();			// setdevice method			void SetDevice(IDirect3DDevice9 *pD3DDevice);			//This updates the world matrix 			void Update(void);			//Returns each of the matrices, WORLD, TRANSLATION, ROTATION, SCALE			D3DXMATRIX GetWorldMatrix(void);			D3DXMATRIX GetTranslationMatrix(void);			D3DXMATRIX GetRotationMatrix(void);			D3DXMATRIX GetScaleMatrix(void);			//Returns each of the vectors, TRANSLATION, ROTATION, SCALE			D3DXVECTOR3 GetTranslationVector3(void);			D3DXVECTOR3 GetRotationVector3(void);			D3DXVECTOR3 GetScaleVector3(void);			//Sets the absolute translation of the node			void SetAbsoluteTranslation(D3DXVECTOR3 v);			void SetAbsoluteTranslation(float x, float y, float z);			//Sets the abosulte rotation of the node			void SetAbsoluteRotation(D3DXVECTOR3 v);			void SetAbsoluteRotation(float x, float y, float z);			//Sets the absoulte origin of the node			void SetAbsoluteOrigin(D3DXVECTOR3 v);			void SetAbsoluteOrigin(float x, float y, float z);			//Sets the absolute scale of the node			void SetAbsoluteScale(D3DXVECTOR3 v);			void SetAbsoluteScale(float x, float y, float z);			//Sets the relative translation of the node			void SetRelativeTranslation(D3DXVECTOR3 v);			void SetRelativeTranslation(float x, float y, float z);			//Sets the relative rotation of the node			void SetRelativeRotation(D3DXVECTOR3 v);			void SetRelativeRotation(float x, float y, float z);			//Sets the relative origin of the node			void SetRelativeOrigin(D3DXVECTOR3 v);			void SetRelativeOrigin(float x, float y, float z);			//Sets the relative scale of the node			void SetRelativeScale(D3DXVECTOR3 v);			void SetRelativeScale(float x, float y, float z);			//Inheritable render method			virtual bool Render(void);			//Turns on the bounding box for rendering			void DebugData(bool debug);			//Gets the position of the bounding box			virtual D3DXVECTOR3 GetPosition(void);			//Gets the dimension of the bounding box			virtual D3DXVECTOR3 GetDimension(void);		/* PROTECTED METHODS */		protected:			//Inheritable method, called when a node is updated			virtual void OnUpdate(void);			//This calculates the points after translation, rotation, scale			//The child class of this class passes in all the points in			//the OnUpdate inherited method			virtual void CalculatePoints(D3DXVECTOR3 *original, D3DXVECTOR3 *points, int length);			//Bounding Box Information			bool							 m_bRenderVolume;			xCustomVertex::PositionColored   m_VerticesColored[4];			D3DXVECTOR3						 m_v3Position, m_v3Dimension;			D3DXMATRIX						 m_matBBWorld, m_matBBTranslation, m_matBBScale, m_matBBRotation;			IDirect3DVertexBuffer9			*m_pVB;			IDirect3DIndexBuffer9			*m_pIB;			short							 m_sIndices[8];			D3DCOLOR						 m_PointColors[4];			//Sets up the indices for the bounding box			virtual void SetupBoundingBoxIndices(void);			//Sets up the vertices for the bounding box			virtual void SetupBoundingBoxVertices(void);			//Sets up the bounding box position and dimension			virtual void SetupBoundingBox(D3DXVECTOR3 position, D3DXVECTOR3 dimension);			virtual void SetupBoundingBox(float x, float y, float z,				float width, float height, float depth);			//Renders the bounding box			virtual void RenderBoundingBox(void);			//Calculates the points of the bounding box			virtual void CalculateBoundingBoxFromPoints(D3DXVECTOR3 *points, int length);		};	//End class xSceneNode	}	//End namespace Base}	//End namespace Impulse#endif


Input class cannot see methods
//===============================================================================================////	File : xInputDevice.h////	Date Created  : 7/14/2005//	Date Modified : 7/14/2005////===============================================================================================////	Handles input from the keyboard or mouse////===============================================================================================#ifndef _XINPUTDEVICE_H_#define _XINPUTDEVICE_H_#include "Impulse.h"using namespace Impulse::Base;namespace Impulse{	namespace Input	{		enum DeviceType		{			DT_KEYBOARD	= 0,			DT_MOUSE	= 1		};		class xInputDevice : public Impulse::Base::xObject		{		/* PRIVATE MEMBER VARIABLES */		private:			IDirectInput8		*m_pDI;				//DirectInput Object			IDirectInputDevice8 *m_pDIDevice;		//DirectInput Device			HWND				 m_hWnd;			//Window Handle			unsigned char		 m_State[256];		//State of keyboard			DIMOUSESTATE		*m_MouseState;		//State of mouse			long				 m_XPos, m_YPos;	//Position of mouse			bool				 m_Windowed;		//Windowed or not			bool				 m_Clicked;			//If mouse was clicked			DeviceType			 m_deviceType;		//Device type			long				 m_DeviceSize;		//Device Size			DIDATAFORMAT		*m_DataFormat;		//Data format of the Device		/* PRIVATE METHODS */			//Create a direct input device			bool CreateInputDevice(void);			//Initializes the keyboard device type			bool InitializeKeyboard(void);			//Initializes the mouse device type			bool InitializeMouse(void);		/* PUBLIC METHODS */		public:			/* CONSTRUCTOR */			xInputDevice(HWND hWnd, IDirectInput8 *pDI, bool Windowed = true, 				DeviceType type = DT_KEYBOARD);			//Clears out the device			void Clear(void);			//Reads the input device			bool Read(void);			//Gets the key state of a key press			bool KeyState(unsigned long Key);						//Gets the button state of a mouse press			bool GetButtonState(unsigned long Button);			//Returns if the mouse has been clicked			bool OnClick(void);			//Gets the position of the mouse			long GetXPos(void);			long GetYPos(void);			long GetXDelta(void);			long GetYDelta(void);		/* PROTECTED METHODS */		protected:			//Inherits from xObject, releases memory			virtual void Dispose(bool disposing);		};	}	//End Input Namespace}	//End Impulse Namespace#endif
If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
Quote:
using namespace Impulse::Base;

namespace Impulse
{

namespace Input
{


this is the offending region. The compiler thinks You are using Impulse::Base::Impulse::Input. Remove "using namespace Impulse::Base" and you should be fine. If you really want to keep it, put it after the class declaration, but I wouldn't recomended it in a header file.
I just barely added that to see if it would need a reference or something. It still gives me the problem without it.
If you insist on saying "DUH", try to make a post that makes a little more sense
what error exactly?
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(274): error C2660: 'Impulse::Sprites::xLabel::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(273): error C2660: 'Impulse::Sprites::xLabel::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(272): error C2660: 'Impulse::Sprites::xLabel::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(271): error C2660: 'Impulse::Sprites::xLabel::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(289): error C2660: 'Impulse::Input::xInputDevice::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(287): error C2660: 'Impulse::Managers::xDeviceManager::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(290): error C2660: 'Impulse::Managers::xInputManager::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(243): error C2660: 'Impulse::Managers::xSceneManager::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(245): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(246): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(247): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(248): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(249): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(250): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(251): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(252): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(253): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\WinMain.cpp(254): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments
c:\Documents and Settings\abc\My Documents\MyProjects\DirectX\C++\ImpulseTetris\Block.cpp(180): error C2660: 'Impulse::Primitives::xQuad::Dispose' : function does not take 0 arguments

If you insist on saying "DUH", try to make a post that makes a little more sense
Try calling the protected, virtual Dispose function something different.
What's happening is pretty simple, actually. The virtual dispose function is trumping the inherited dispose function during overload resolution. Because the virtual function is present right in the class, it always wins, even when the parameters aren't right.

You could change the name of the non-virtual function; Or if you are only calling it from derived functions you could call it using Base::Dispose().
Thanks a lot that was it. why can't I see the other methods, like GetName called Name, and GetId call UniqueID in intellisense, thats what was throwing me off was stupid intellisense.

Well I got the shutdowns working releasing the memory when the window is closed, but that didn't solve my original issue, it errors out saying memory can;t be read from so and so place, probably because I still have something still active. But thats for another day.
If you insist on saying "DUH", try to make a post that makes a little more sense
You can't see them in intellisense because the intellisense is not smart enough. The only way to know for sure what a class would have in all but the most basic cases is too compile the code, and intellisense isn't doing that. It just parses it and does the best it can. If it's not sure about something, it leaves it out. Better to not have it at all then have it wrong. DevCpp's intellisense is somewhat better than VS, and works more consistently, but VS does all the parsing on the fly and, if you've installed Devcpp, you are familiar with the time it takes it to build the intellisense database the first time around.

This topic is closed to new replies.

Advertisement