1,105,556 Community Members

abstract class - virtual function

Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
jaskij
Junior Poster
105 posts since Oct 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
jaskij
Junior Poster
105 posts since Oct 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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;
};
Member Avatar
jaskij
Junior Poster
105 posts since Oct 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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...

Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
jaskij
Junior Poster
105 posts since Oct 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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...)

Member Avatar
jaskij
Junior Poster
105 posts since Oct 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Tumlee
Posting Whiz in Training
203 posts since Oct 2011
Reputation Points: 42 [?]
Q&As Helped to Solve: 41 [?]
Skill Endorsements: 4 [?]
 
1
 

"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;
}
Member Avatar
Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Question Answered as of 2 Years Ago by jaskij and Tumlee
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: