Boost logo

Boost Users :

Subject: Re: [Boost-users] Help with Visual Studio settings for BoostSerialization
From: Abdullah ARSLAN (abdullaharslan_at_[hidden])
Date: 2010-12-05 10:24:30


You suggest putting everything in header file. But in the documentation
example, all the code is in a demo.cpp file.
Besides, i still get same error if i put function definition to header file.
The only solution currently is to write all the class code in a single cpp
file (without .h file). I am not much familiar with c++. But I think there
must be a way of separating the declaration and definition of the template
function.

Any idea?

Abdullah Arslan
Software Engineering and Management Master Program, University of Göteborg

On Sun, Dec 5, 2010 at 2:49 AM, Edward Diener <eldiener_at_[hidden]>wrote:

> On 12/4/2010 6:49 PM, Abdullah ARSLAN wrote:
>
>> you seem to be right.
>> I was using a header file for class declaration and a cpp file for
>> definition, when i moved everything to cpp file,
>> It worked.
>>
>> But what is the problem? My header file contains
>> template<class Archive>
>> void serialize(Archive & ar, const unsigned int version);
>>
>> and in cpp file
>> template<class Archive>
>> void g7GameObject::serialize(Archive & ar, const unsigned int version)
>> {
>> ar & height;
>> ar & width;
>> ......
>> } // my class name is g7GameObject
>>
>> and with above code i get following error
>> error LNK2019: unresolved external symbol "private: void __thiscall
>> g7GameObject::serialize....
>>
>> What am i doing wrong
>>
>
> In the typical template inclusion model, both the template declaration and
> the template definition need to be in a header file so that soure using the
> template can include that header file and get the full template code. If you
> put the definition in a source file it is quite likely that code which uses
> that template never "include"s that source file and therefore the template
> definition is missing when you link.
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net