Hi Rooters
I have a Record Class that has a member called:
vector<UserObject> fUserData;
In a single library package.
I then want to allow users to be able to create thier own classes that inherit for UserObject (which does not inherit from TObject) and add them to this vector and have them written out.
UserObejct looks like this:
namespace SoCal{
class UserObject{
public:
UserObject(const char* name);
UserObject(const std::string& name);
virtual ~UserObject(){return;}
virtual const std::string& Name()const{ return pName;}
virtual void SetName(const char* name){pName = name;}
virtual void SetName(const std::string& name){pName = name;}
protected:
std::string pName;
};
}[/code]
And I have this line in my LinkDef.h file:
[code]#pragma link C++ class SoCal::UserObject!;[/code]
I compile the library and everything is great.
However, When it comes to adding a users class which will be compiled into a different library, e.g.:
[code]
#include "Event/UserObjects.h"
class MyClass : public SoCal::UserObject{
public:
MyClass();
virtual ~MyClass();
int dIndex;
};
[/code]with a linkdef.h that looks like:
[code]#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class MyClass+;
[/code]
I find that when I try create some MyClass's and stick them in Record to be written out, they write out fine. However, when I try read them back in I find that I am unable to do so. I get the error message:
[code]Error in <TBuffer>: got wrong class: MyClass
Error in <TBuffer>: got object of wrong class! requested SoCal::UserObject but got MyClass
My question is, what am I doing wrong? Is the reading and writing of a vector of pointers to things that dont inhertit from TObject even supported?
Root: V.5.11/01
Intel mac , gcc v4.0
Cheers
Caius