We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,167 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

abstract class - virtual function

Hello, I need to update my older Autodesk plug-in. And I am having troubles get it through. (They changed one function)

This is a new definition which I cannot change:

CoreExport virtual void EnumAuxFiles(AssetEnumCallback& assetEnum, DWORD flags);

And here is my code:

class CheckFileNames: public AssetEnumCallback {
public:
	NameTab* missingMaps;
	BitmapInfo bi;
	CheckFileNames(NameTab* n);
	void RecordName(TCHAR *name);
};

CheckFileNames::CheckFileNames(NameTab* n)
{
	missingMaps = n;
}

int LoadMapFiles(INode* node, SContext* sc, MtlBaseLib& mtls, TimeValue t)
{
	NameTab mapFiles;	
	CheckFileNames checkNames(&mapFiles);  // HERE is the bug
     //error C2259: 'CheckFileNames' : cannot instantiate abstract class

	node->EnumAuxFiles(checkNames, FILE_ENUM_MISSING_ONLY |FILE_ENUM_1STSUB_MISSING);
}

My C++ is quite rusty by now, but if I understand it correctly: the new definition is a pure virtual function which makes my class abstract.
How do I correct it ?
(Perhaps I should inherit from my class somehow, but what is the proceeding ?)
Thank you very much for any kind of help.

3
Contributors
11
Replies
2 Hours
Discussion Span
1 Year Ago
Last Updated
12
Views
Question
Answered
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

What you have there is not a pure virtual function, but just virtual function.
A purely virtual function would be like: CoreExport virtual void EnumAuxFiles(AssetEnumCallback& assetEnum, DWORD flags)=0; .
A simple virtual function means only one thing: it can be re-defined by it's child classes.

There is a good description of this at cplusplus.com, if my explanation wasn't enough.

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

Thank you. Yes you are absolutely right, but why Am I getting - cannot instantiate abstract class error ?

Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hard to say, but my guess is you don't implement a pure virtual function that is in the class from which you inherit. Could you give a link to docs?

Also, for more extensive error descriptions, just google "Visual Studio error" adding the error you get. Microsoft provides nice descriptions, which sometimes are pretty helpful. Not this time though.

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

Good idea. So here is the error descrition.

'CheckFileNames' : cannot instantiate abstract class
due to following members:
'void AssetEnumCallback::RecordAsset(const MaxSDK::AssetManagement::AssetUser &)' : pure virtual function was not defined
c:\Program Files\Autodesk\3ds Max 2012\maxsdk\include\AssetEnumCallback.h(41) : see declaration of 'AssetEnumCallback::RecordAsset'

Adn here is the code:

namespace MaxSDK
{
	namespace AssetManagement
	{
		class AssetUser;
	}
}

// A callback object passed to EnumAuxFiles().

class AssetEnumCallback : public MaxHeapOperators
{
public:
	/*! \remarks Destructor. */
	virtual ~AssetEnumCallback() {}
	/*! \remarks This method is used to record the asset passed.
	\par Parameters:
	<b>const MaxSDK::AssetManagement::AssetUser& asset</b>\n\n
	The asset to store. */
	virtual void RecordAsset(const MaxSDK::AssetManagement::AssetUser& asset)=0;
};
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

As you can see, you should implement the RecordAsset() method.

Take a look here: http://download.autodesk.com/global/docs/3dsmaxsdk2012/en_us/index.html

No idea what it does though, I suppose this has something to do with 3dsMax's internal management or what...

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

I am pretty hopeless...
Here is th only def. I found.

Animatable::EnumAuxFiles() - a developer derives a class from this class and implements the RecordAsset() method to store each asset as it's passed to it.

How do I add it just to compile correctly?

Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Just make an empty method or something, should work IMO.

The question here is, how will that work with Max.
Since the arg is a const reference it shouldn't have much of an impact though.

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

"Just make an empty method" I would need a little help. How to do it ?
(I know it sounds stupid but I haven't touched c++ in 10 years...)

Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

No problem ;P

Inside your class:

void RecordAsset(const MaxSDK::AssetManagement::AssetUser& asset){
int a;
}

Sorry for the lack of indentation, wrote it in the forum posting box.

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

"Just make an empty method" I would need a little help. How to do it ?
(I know it sounds stupid but I haven't touched c++ in 10 years...)

You would just make a function put nothing in the brackets except for a return; statement in this case. If the function was non-void you'd probably want it to return an actual value. The following should probably work:

void CheckFileNames::RecordAsset(const MaxSDK::AssetManagement::AssetUser& asset)
{
    return;
}
Tumlee
Junior Poster
172 posts since Oct 2011
Reputation Points: 84
Solved Threads: 32
Skill Endorsements: 3

Och, so simple. (definitively not my day today :) )
Thank you very much for the help.

Now I must run series of tests if Autodesk's new RecordAsset has any impact...

Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by jaskij and Tumlee

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0876 seconds using 2.68MB