저는 G ++에서 작동하지만 Visual Studo 2008에서는 컴파일되지 않습니다.연산자가있는 호기심 반복 템플릿
template<typename T, typename DerivedT >
struct Foo
{
template<typename Scale>
DerivedT operator * (const Scale i)
{
DerivedT result;
return result;
}
};
template<typename T>
struct Bar : public Foo<T, Bar<T> >
{
// Removing this operator gets rid of the error.
Bar& operator * (const Bar& boo)
{
return *this;
}
};
int main()
{
Bar<float> bar;
bar = bar * 3;
return 0;
}
나는 내가 INT/더블로 푸 연산자를 정의하는 경우에도 오류를
Error 1 error C2679: binary '*' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
를 얻을 수 /이 같은 오류 메시지를 반환 명시 적으로 부동. 이 과거를 지나치는 방법이 있습니까?
편집 : 파생 클래스가 기본 클래스에서 정의 된 연산자 *를 오버로드하는 경우에만 해체됩니다.
사례 연구보기 또는 도움을 드릴 수 없습니다. – Puppy
@DeadMG 이것은 내 테스트 케이스이며, 그냥 다듬은 것입니다. 누락 된 정보 중 일부를 채웠습니다 –