Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ledneh

Base class undefined? HELP!

This topic is 5737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, building a D3D App. I have two objects: CObject and CBlock (declared/defined in Object.h/cpp and Block.h/cpp, respectively). CBlock, in theory, is supposed to inherit from CObject (which, by the way, has one of those "undefined" functions, I forget what they''re called... Code''s posted below, let me know if you know). However, the code below gives a "''CObject'': Base class undefined" error. Help: Object.h
#pragma once

#include "Direct3D.h"
#include <time.h>

class CObject
{
public:
	virtual void Update();
	virtual void Render()=0;
	CObject();
	~CObject();

// ...and so forth... //
};
 
Block.h
#pragma once

#include "Direct3D.h"
#include "Object.h"

class CBlock : public CObject
{
public:
	CBlock();
	~CBlock();

	void Render();

private:
	int m_blockX; // in relation to playing field
	int m_blockY;
	D3DCOLOR m_color; // make this completely random?
};
 
That''s it. If anyone can help, I''d appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
They're pure virtual functions. And base class destructor should be virtual. Otherwise this'll happen:
  
CObject* object = new CBlock();
delete object; //!!!ALERT, CBlock destructor won't be called


But that doesn't solve your problem. It might have something to do with the "#pragma once"s..

[Edit: The [source] tag, however, is not intended for code snippets that fit within the window width and are less than 10 lines long... People find it irritating. ]

[edited by - Oluseyi on October 4, 2002 6:33:08 PM]

Share this post


Link to post
Share on other sites
Why is there no "=0" after Update(); in CObject.h?
(how does this =0 work?)

And ehrm, why are there no Update and render functions in the CBlock object?

Share this post


Link to post
Share on other sites
I didn't include the definitions, simply because it would only cause needless spam. Block.cpp includes Block.h, and Object.cpp includes Object.h.

Also, CObject::Update() isn't pure virtual because it IS defined in Object.cpp--CObject::Render() is the only one meant to be pure virtual.

[edited by - Ledneh on October 2, 2002 4:47:23 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I hope you didn''t miss my comment about base class destructors...

Share this post


Link to post
Share on other sites
I got it, thanks. Just a silly bit of forgetfulness on my part, there. Still lost on the base class error, though.

Share this post


Link to post
Share on other sites
Something that''s probably pretty obvious, but the error only occurs when Block.h is included anywhere in my project. Including Object.h doesn''t help (or cause) this error.

Share this post


Link to post
Share on other sites
  • Is there anything in Direct3D.h that might cause the preprocessor to look over CObjects definition (like an #ifdef/#ifndef without a matching #endif)?


  • In which cpp file does the error occur?


  • What complier are you using?



  • [edited by - Solo on October 2, 2002 11:24:41 PM]

    Share this post


    Link to post
    Share on other sites

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    Participate in the game development conversation and more when you create an account on GameDev.net!

    Sign me up!