I am public deriving two instances of class template 'Area', one int and another char into an separate class 'Rectangle'.
template<class T>
class Area {
public:
T a;
T getArea() { return a; }
void setArea(T t) { a = t; }
};
class Rectangle : public Area<int>, public Area<char> {
};
int main() {
Rectangle a;
a.setArea(1);
std::cout << a.getArea() << std::endl;
Rectangle b;
b.setArea('c');
std::cout << b.getArea() << std::endl;
}
And I see ambiguity with setArea and getArea. Why is that so? I thought after public Area, public Area there would be two definitions of setArea. First, void setArea(int) and another void setArea(char). Please correct me if I am wrong. And If I am correct, why the ambiguity?
a.getArea()you meant to call. Try helping it:std::cout << a.Area<char>::getArea() << std::endl;- Mihai Todor