I am running into this error and not sure how to solve this. What I try to do is to overload the template class function. I think the compiler need some help to determine the type but I'm not sure how.
please any help is appreciated.
thanks
Error in VS 2015; line 41, 47, 53
Error C2664 'void BigALittleA::process(const BigA &,LittleA &)': cannot convert argument 1 from 'const BigB' to 'const BigA &' test c:\test\test\test.h 41 Error C2664 'void BigALittleB::process(const BigA &,LittleB &)': cannot convert argument 1 from 'const BigB' to 'const BigA &' test c:\test\test\test.h 47
Error C2664 'void BigBLittleB::process(const BigB &,LittleB &)': cannot convert argument 1 from 'const BigA' to 'const BigB &' test c:\test\test\test.h 53
Test.h
#ifndef _TEST_H_
#define _TEST_H_
class BigA {};
class BigB {};
class LittleA {};
class LittleB {};
template <typename T1, typename T2>
class Base {
public:
void process(const T1& t1, T2& t2) {};
};
class BigALittleA : public Base <BigA, LittleA> {
public:
void process(const BigA& t1, LittleA& t2) {};
};
class BigALittleB : public Base <BigA, LittleB> {
public:
void process(const BigA& t1, LittleB& t2) {};
};
class BigBLittleB : public Base <BigB, LittleB> {
public:
void process(const BigB& t1, LittleB& t2) {};
};
class TestMyStuff {
public:
template <typename T>
void testMyStuff(const T& t, int whichClass)
{
switch (whichClass)
{
case 1: // BigALittleA
{
LittleA a;
Aa.process(t, a); // line 41
break;
}
case 2: // BigALittleB
{
LittleB b;
Ab.process(t, b); // line 47
break;
}
case 3: // BigALittleB
{
LittleB b;
Bb.process(t, b); // line 53
break;
}
}
}
private:
BigALittleA Aa;
BigALittleB Ab;
BigBLittleB Bb;
};
#endif
Test.cpp
#include "Test.h"
int main(int argc, char** argv) {
TestMyStuff tms;
BigA A;
tms.testMyStuff(A, 1);
tms.testMyStuff(A, 2);
BigB B;
tms.testMyStuff(B, 3);
return 0;
}
Comments
Post a Comment