Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: blackhole on January 20, 2009, 04:18:24 am

Title: Explicit Specialization
Post by: blackhole on January 20, 2009, 04:18:24 am
Code: [Select]
  struct QA_DLLEXPORT cAnimEquation : cHolder<cAnimScript>, public cFileIO
  {
  public:
    cAnimEquation(const cAnimEquation& copy);
    cAnimEquation(QAnim::cAnimScript *script=0);
    cAnimEquation(cAnimScript* script, const cAnimTerm* terms);
    ~cAnimEquation();
    template<class T>
    T ResolveT() const;

Code: [Select]
template<>
double cAnimEquation::ResolveT<double>() const
{
  return COP(cAnimScript)->EqResolve<double>(_terms);
}

Produces

Code: [Select]
error C2908: explicit specialization; 'T QAnim::cAnimEquation::ResolveT<double>(void)' has already been instantiated d:\erik's documents\visual studio 2008\projects\qasm\qanim\canimequation.cpp 40
error C2910: 'QAnim::cAnimEquation::ResolveT' : cannot be explicitly specialized d:\erik's documents\visual studio 2008\projects\qasm\qanim\canimequation.cpp 36

What the ****ing ****.

I have checked the stupid syntax for explicit specialization a bajillion times, i've taken the const off the function, i've made the function return void and instead have a paramater, all to no avail. What in the holy sh!ttacos of hell is going on here?!

EDIT: Found workaround to avoid explicit specialization, but this still weirds me out.
Title: Re: Explicit Specialization
Post by: Uchuujinsan on January 20, 2009, 01:12:10 pm
Im not an expert with templates, but after looking at http://msdn.microsoft.com/en-us/library/0w9xyawz(VS.80).aspx , I wonder if some include is there, that shouldnt be..?

Basically, the compiler already generated the code for type <int> when he got to the lines you posted, so, well, its an error. Or am I misunderstanding your problem? :>
Title: Re: Explicit Specialization
Post by: blackhole on January 20, 2009, 04:38:34 pm
Basically, the compiler already generated the code for type <int> when he got to the lines you posted, so, well, its an error. Or am I misunderstanding your problem? :>

That is exactly why it is impossible. If I remove the template code there, I will get a link error because the code hasn't been generated. If I include the template code, it says its already been generated.
Title: Re: Explicit Specialization
Post by: lurcher on January 20, 2009, 08:33:12 pm
I am getting the same kind of error - can you post what your workaround is? Thanks!
Title: Re: Explicit Specialization
Post by: WMCoolmon on January 20, 2009, 11:48:44 pm
I did this:
Code: [Select]
struct cAnimEquation
{
template<class T>
    T ResolveT() const;
};

template<class T>
T cAnimEquation::ResolveT() const
{
return 0.0;
}

template<>
double cAnimEquation::ResolveT<double>() const
{
return 0.0;
}

int main()
{
return 0;
}

Worked fine.

Also tried:
Code: [Select]
struct cHolder
{
template<class T>
T ResolveT() const;
};

template<class T>
T cHolder::ResolveT() const
{
return 0.0;
}
template<>
double cHolder::ResolveT<double>() const
{
return 0.0;
}

struct cAnimEquation : public cHolder
{
template<class T>
    T ResolveT() const;
};

template<class T>
T cAnimEquation::ResolveT() const
{
return 0.0;
}

template<>
double cAnimEquation::ResolveT<double>() const
{
return 0.0;
}

int main()
{
return 0;
}

and it still worked fine.

What happens if you comment out
Code: [Select]
return COP(cAnimScript)->EqResolve<double>(_terms);
and replace it with a constant?
Title: Re: Explicit Specialization
Post by: blackhole on January 21, 2009, 03:03:11 am
I am getting the same kind of error - can you post what your workaround is? Thanks!

My workaround is program specific and unlikely to be of much help.

If I comment out that line nothing happens.