By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

Problem with multiple parameter templates and function overloading

P: n/a
I have written the following very short template class in testclass.h:

template<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
};

template<typename C,typename T>
T TestClass<C,T>::testFunction(T dummy)
{
C bla;
return dummy;

}

So far it compilates fine.
Now i want to overload the testFunction:

template<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(double dummy);
};

template<typename C,typename T>
T TestClass<C,T>::testFunction(T dummy)
{
C bla;
return dummy;

}

/* now comes the problematic part */

template<typename C>
double TestClass<C,double>::testFunction(double dummy)
{
C bla;
return dummy;
}

I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFunction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFunction(double)'

If I remove the parameter C everything works fine of course.
Please can anybody help me.
I think its probably just a small problem.

Sep 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

ny*****@hotmail.com wrote:
I have written the following very short template class in testclass.h:

template<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
};

template<typename C,typename T>
T TestClass<C,T>::testFunction(T dummy)
{
C bla;
return dummy;

}

So far it compilates fine.
Now i want to overload the testFunction:

template<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(double dummy);
};

template<typename C,typename T>
T TestClass<C,T>::testFunction(T dummy)
{
C bla;
return dummy;

}

/* now comes the problematic part */

template<typename C>
double TestClass<C,double>::testFunction(double dummy)
{
C bla;
return dummy;
}
Your testFunction is not a template function. I am not quite sure what
you are trying to do, but the bottom line is you have a template class.

So, if you want to have a specialized testfunction implementation for
double, then first specialize the template class TestClass for double
and then have an implementation for that.

Look up partial specialization (function templates cannot support them)
something like this...

template<typename C>
class TestClass<C, double>
{
public:
double testFunction(double dummy);
};

template<typename C>
double TestClass<C,double>::testFunction(double dummy)
{
C bla;
return dummy;
}
>
I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFunction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFunction(double)'

If I remove the parameter C everything works fine of course.
Please can anybody help me.
I think its probably just a small problem.
Sep 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.