0

I have a class myclass and a function serialize. i am unable to call function of myclass.

Function declaration in class:

        class myclass
        {
        int x,y,z;
        template<class Archive> void serialize(Archive & ar, const unsigned int=0 );

        }

        Function Definition:
        template<class Archive>void  myclass::serialize( Archive & ar,
                                                  const unsigned int)
        {
                ar & x;
                ar & y;
                ar & z;
        }

How to call the function serialize? I have tried to call it like this:

myclass obj;  //object of my class
boost::archive::binary_oarchive ar(std::cout);
obj.serialize (ar); //calling serialize

But is is giving me the below error: undefined reference to `void myclass::serialize

  • If that definition isn't in the same translation unit, then http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris Mar 07 '14 at 05:42
  • That is not the issue. Undefined reference is due to there is some mismatch in the parameter of the function i am calling and the actual function. I have tried n modified the argument of the same func and the called it. There is no undefined reference then. – user3069523 Mar 07 '14 at 05:54
  • Well, it would be an issue. Defining function templates in a different "file" will not work. As seen in the link, there are plenty of ways to trigger that linker error, and a mismatch in parameter vs argument would more likely be a compiler error. – chris Mar 07 '14 at 06:36

0 Answers0