Author Topic: Explicit Specialization  (Read 3910 times)

0 Members and 1 Guest are viewing this topic.

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Explicit Specialization
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.
« Last Edit: January 20, 2009, 04:27:14 am by blackhole »

 
Re: Explicit Specialization
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? :>

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Explicit Specialization
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.

 

Offline lurcher

  • 20
Re: Explicit Specialization
I am getting the same kind of error - can you post what your workaround is? Thanks!

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Explicit Specialization
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?
-C

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Explicit Specialization
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.