On Jul 29, 6:31*pm, Jonathan Lee <jonathan.lee....@gmail.com> wrote:
> On Jul 29, 12:39*pm, Immortal Nephi <Immortal_Ne...@hotmail.com>
> wrote:
>
> > * * * * I wrote class Data in header. *The C++ Compiler compiled without
> > errors. *I decided to move all member functions into source code
> > because they are for implementation. *I do not like that they are
> > placed in class body.
>
> > * * * * I got error message:
>
> > Linking...
> > Main.obj : error LNK2001: unresolved external symbol "public:
> > __thiscall Data<unsigned char>:
perator unsigned char(void)" (??B?
> > $Data@E@@QAEEXZ)
> > C:\Main.exe : fatal error LNK1120: 1 unresolved externals
>
> > * * * * Could be problem with member function cast operator. *All other
> > member functions complied without any problems.
>
> GCC compiled this without a complaint, so it's legal-ish (?).
> BUT you have 3 specializations declared in data.cpp without
> definitions. Maybe MS is expecting the definitions.
>
> (I actually have no idea if this is legal or not since I've
> never declared a specialization and not immediately implemented
> it).
>
> --Jonathan
Is this right, what you are proposing here? If you look back at the
OP's
code, what he provided were not specializations at all, but rather
*explicit instantiations*, including:
template< typename T > // primary template
Data< T >:

perator unsigned char() {
return x;
}
template // explicit inst. for uchar
Data< unsigned char >:

perator unsigned char();
I'm not that up to speed on this because I have never found myself
using
explicit instantiations. Still, it is not my /expectation/ that any
further `implementation' is required here. The OP's code is, surely,
merely saying "I have this template. I shall be needing to use it on
Data< unsigned char>. Instantiate the relevant member functions (ctor,
dtor, op uchar) for me." Of course, this is necessary here, owing to
the
fact that the primary definitions are themselves present in a source,
rather than a header, file. Beyond that, I'm not immediately seeing
that there is any problem with this.
Regards
Paul Bibbings