- шаблонированный тип класса T< /li>
bool
template
virtual container_t foo(const R& value1, const T& value2) const = 0;
Но следующее не строится с T = bool, поскольку вызов foo становится неоднозначным. Как мне решить эту проблему?
#include
#include
template
class BaseClass {
public:
virtual container_t foo(const T& value1, const T& value2) const = 0;
virtual container_t foo(bool value1, const T& value2) const = 0;
container_t bar_t() const {
return foo(T(0), T(0));
}
container_t bar_bool() const {
return foo(false, T(0));
}
};
template
class DerivedClass : public BaseClass {
public:
using BaseClass::bar_t;
using BaseClass::bar_bool;
DerivedClass() {}
std::vector foo(const T& value1, const T& value2) const override {
return std::vector(8, value1);
}
std::vector foo(bool value1, const T& value2) const override {
return std::vector(8, value1);
}
};
int main() {
DerivedClass int_instance;
std::cout main.cpp(9,31): message : could be 'std::vector BaseClass::foo(bool,const T &) const'
1> with
1> [
1> T=bool
1> ]
1>main.cpp(8,28): message : or 'std::vector BaseClass::foo(const T &,const T &) const'
1> with
1> [
1> T=bool
1> ]
1>main.cpp(15,1): message : while trying to match the argument list '(bool, T)'
1> with
1> [
1> T=bool
1> ]
1>main.cpp(14): message : while compiling class template member function 'std::vector BaseClass::bar_bool(void) const'
1> with
1> [
1> T=bool
1> ]
1>main.cpp(45): message : see reference to function template instantiation 'std::vector BaseClass::bar_bool(void) const' being compiled
1> with
1> [
1> T=bool
1> ]
1>main.cpp(20): message : see reference to class template instantiation 'BaseClass' being compiled
1> with
1> [
1> T=bool
1> ]
1>main.cpp(43): message : see reference to class template instantiation 'DerivedClass' being compiled
Подробнее здесь: https://stackoverflow.com/questions/790 ... ated-class