Sign in to follow this  
flery

abstract class problem

Recommended Posts

Hi, i am trying to write an abstract class (within a dll). as far as i can tell i would say everything is correct but the compiler begs to differ... I get the following error: "Error 4 error LNK2019: unresolved external symbol "public: virtual bool __thiscall f3dLinList::UnloadFile(void *)" (?UnloadFile@f3dLinList@@UAE_NPAX@Z) referenced in function "public: __thiscall f3dLinList::~f3dLinList(void)" (??1f3dLinList@@QAE@XZ) f3dLinList.obj" i tried to recreate the error outside the project without success. the header of my abstract class looks like this
#pragma once
#include "f3dDefault.h"


struct f3dapi f3dLinListElem {
	f3dLinListElem* pPrevious;
	char			cFilename[255];
	void*			pContent;
	unsigned int	uiRefCount;
	f3dLinListElem* pNext;
};

// MAKE ABSTRACT
class f3dapi f3dLinList
{
public:
	f3dLinList(void);
	~f3dLinList(void);
	bool			Add(char* inc_cFilename);
	void*			Remove(char* inc_cFilename);
	f3dLinListElem*	Search(char* inc_cFilename);
	void			DebugPrint();
	virtual void*	LoadFile(char* inc_cFilename) = 0;
	virtual bool	UnloadFile(void* pFile) = 0;

private:
	unsigned int	uiElemCount;
	f3dLinListElem*	pCurrentElem;
	f3dLinListElem*	pFirstElem;
	f3dLinListElem*	pLastElem;

};


everything works fine as long as i dont use the virtual functions in the f3dLinList class. if i try to use them i get the described error. the derived class has both functions. i hope i made myself clear as english is not my native language. mfg flery

Share this post


Link to post
Share on other sites
Quote:
Original post by Desdemona
This looks suspiciously like C++, and yet the syntax "class f3dapi f3dLinList" just doesn't clash. ;p

Might I suggest something a bit more standard like "class f3dapi: public f3dLinList"?

D

I don't understand why you would suggest anything like that. And I'm not sure why you don't think that looks like C++ because it seems perfectly fine. At first glance it seems that f3dapi is a #define for the declspec used in DLL export/importing.

Share this post


Link to post
Share on other sites
based on this error I'm assuming you're trying to call your pure virtual function inside your destructor. You can't do this because the function technically doesn't exist inside this class since it's pure virtual. You'll have to either make it virtual (i.e. _not_ pure virtual) or simply not call it inside your destructor.

Share this post


Link to post
Share on other sites
i can use the virtual (abstract) functions only outside the destructor and constructor ? i thought writing the functions as virtual, overwriting and using them is the whole point of creating abstract classes.

my idea was like that as i derive a class from the abstract class f3dLinList the new class inherits all functions except the (pure) virtual ones which i define inside my new class.

#pragma once

// EXAMPLE OF AN ABSTRACT CLASS
// Info: See 'subCore' class for derived 'core' class

class core
{
public:
int core::test();
int core::bla;
virtual int test2(int bla) = 0;
};

#pragma once
#include "core.h"

// DERIVED CLASS
// of abstract class core

class subCore : public core
{
public:
subCore(void);
public:
~subCore(void);
int test2(int bla);
};






something like that
the core.cpp file looking like that

[source lang=cpp]
#include "StdAfx.h"
#include "core.h"

int core::test()
{
test2(100);// calling the virtual function
return 0;
}







Update**
okay thanks this seems to be the mistake using the virtual functions in the destructor is not possible...

#include "StdAfx.h"
#include "core.h"

int core::test()
{
test2(100);
return 10;
}

core::~core()
{
test2(100);
}




had to rewrite the destructor (as virtual). is there another way of writing the cleanup code in the abstract class and calling it on distruction ? probably not..
thanks so far
flery

[Edited by - flery on September 9, 2006 12:48:51 AM]

Share this post


Link to post
Share on other sites
well you can never instantiate an abstract class which leads me to believe that calling the pure virtual functions of said class is illegal, pure virtual functions are ones that _must_ be overwritten in any derived class, but are not actually defined in the abstract class.

Anyone else out there that can prove or disprove this theory?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this