Hello,
the following example code uses templates and user defined conversion. It compiles and run correctly on linux using Intel Composer XE 2013 :
template <typename TYPE>
class Adult {
public :
Adult(TYPE years): age(years) {};
TYPE getAge() const {
return age;
}
private :
TYPE age;
};
template <typename TYPE>
class Child {
public :
Child(TYPE years): age(years) {};
TYPE getAge() const {
return age;
}
private :
TYPE age;
};
template <typename TYPE, template <typename T> class PERSON=Child >
class Human: public PERSON<TYPE> {
public:
Human(TYPE years): PERSON<TYPE>(years){};
operator Human<TYPE, Child>() const {
Human<TYPE, Child> res(this->getAge());
return res;
};
TYPE getBirth(TYPE current) const {
return (current - this->getAge());
}
};
int test() {
Human<int,Adult> daddy(30);
Human<int,Child> toto = daddy; // error : type "Child<TYPE>::Child [with TYPE=int]" is not a class template
int birthDate = toto.getBirth(2014);
return birthDate;
}
int main() {
std::cout << "\n--[Athena,"<< test() << "] "; std::cout.flush();
}On Windows, with the same compiler, an error occurs :
test.cpp(43): error : type "Child<TYPE>::Child [with TYPE=int]" is not a class template
test.cpp(43): error : type "Child<TYPE>::Child [with TYPE=int]" is not a class template
operator Human<TYPE, Child>() const {
operator Human<TYPE, Child>() const {
^
detected during instantiation of class "Human<TYPE, PERSON> [with TYPE=int, PERSON=Child]" at line 59
^
detected during instantiation of class "Human<TYPE, PERSON> [with TYPE=int, PERSON=Child]" at line 59
Is there any restriction on template use on windows ? Or does the compiler need some option enabled ?