Archived

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

vc6 template issue

This topic is 5044 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

i have written this code in linux which compiles fine with gcc
class RegBase
{
public:
	virtual Obj* Create()
	{
		return 0;
	}
};

template class ObjReg : public RegBase
{
public:
	ObjReg( const char* classId )
	{
		ObjMgr::Register( classId, (RegBase*)this );
	}

	virtual Obj* Create()
	{
		printf("Creating the class complete@!!!\n");
		return new T;
		//return 0;
	}

protected:

};
 
now the line that is causing issues: "return new T;" this error only occurs when i use the template like: ObjReg regReg("chat"); where chat is a Class i have that extends Obj* the error is: f:\siphongl\engine\objmgr.h(61) : error C2259: ''Chat'' : cannot instantiate abstract class due to following members: maybe there is a patch for vc6 to fix this?

Share this post


Link to post
Share on other sites
The problem is with the Chat class not the ObjReg class.

You need to ensure you have implemented pure virtual functions that are declared in Obj

[edited by - petewood on February 20, 2004 8:44:04 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by _Rambo_
template< class T > // it should work with this
class ObjReg : public RegBase
{
...
}


The forum messed up his code. That wasn''t his problem.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by petewood
The problem is with the Chat class not the ObjReg class.

You need to ensure you have implemented pure virtual functions that are declared in Obj

<SPAN CLASS=editedby>[edited by - petewood on February 20, 2004 8:44:04 AM]</SPAN>


i have?!

[cpp]
class Obj
{
public:
//virtual Obj* Create() = 0;

//virtual Obj* Create() = 0;

virtual void Update( unsigned long tick )
{

}

protected:

};

class NetObj
{
public:
virtual bool Send( void* message, int length ) = 0;
virtual bool Recive( void* message, int length ) = 0;
virtual char* GetClassId() = 0;

void SetNetId( int netId )
{
this->netId = netId;
}

bool IsNetObject()
{
printf("this netobj check has been called\n";
return true;
}

virtual void AnotherFn()
{
printf("Another fn called from NetObj\n";
}
//protected:
friend class Client;

int ownerId; // to identify who is in control of this obj
int netId; //to identify this object on netowkred pc''s
};
[/cpp]

and this is my chat class:
[cpp]
class Chat : virtual public Obj, virtual public NetObj
{
public:
Chat()
{
//notify obj manager
if( ObjMgr::RegisterObject( this ) )
{
//notify client...
client.RegisterNetObject( this );
}

printf("CREATING A NEW CHAT\n";
};

virtual void Update( unsigned long tick )
{
}

bool Send( void* message, int length )
{
return true;
};

bool Recive( void* message, int length )
{
return true;
};

virtual void AnotherFn()
{
printf("Another fn called from Chat\n";
}

virtual char* GetClassId()
{
printf("returning ''chat'' as classid\n";
return "chat";
}
//protected:
//static ObjReg<Chat> regReg; //("chat";
std::string last;
};

//ObjReg<Chat> regReg("chat"; //uncomment this line here and vc6 spits chips
[/cpp]

Share this post


Link to post
Share on other sites
just formatted it for easier reading:


class Obj
{
public:
//virtual Obj* Create() = 0;

//virtual Obj* Create() = 0;

virtual void Update( unsigned long tick )
{
}
protected:
};

class NetObj
{
public:
virtual bool Send( void* message, int length ) = 0;
virtual bool Recive( void* message, int length ) = 0;
virtual char* GetClassId() = 0;
void SetNetId( int netId )
{
this->netId = netId;
}
bool IsNetObject()
{
printf("this netobj check has been called\n");
return true;
}
virtual void AnotherFn()
{
printf("Another fn called from NetObj\n");
}
//protected:

friend class Client;
int ownerId; // to identify who is in control of this obj

int netId; //to identify this object on netowkred pc''s

};


and this is my chat class:

class Chat : virtual public Obj, virtual public NetObj
{
public:
Chat()
{
//notify obj manager

if( ObjMgr::RegisterObject( this ) )
{
//notify client...

client.RegisterNetObject( this );
}
printf("CREATING A NEW CHAT\n");
};

virtual void Update( unsigned long tick )
{
}
bool Send( void* message, int length )
{
return true;
};
bool Recive( void* message, int length )
{
return true;
};
virtual void AnotherFn()
{
printf("Another fn called from Chat\n");
}
virtual char* GetClassId()
{
printf("returning ''chat'' as classid\n");
return "chat";
}
//protected:

//static ObjReg<Chat> regReg; //("chat");

std::string last;
};
//ObjReg<Chat> regReg("chat"); //uncomment this line here and vc6 spits chips


Share this post


Link to post
Share on other sites