所以,我有一个基类:
enum ComparableType
{
CompType_ShaderObject
};
class Comparable
{
public:
Comparable( void ) {};
Comparable( ComparableType ct ) : mComparableType( ct )
{}
inline virtual std::string& getKey( void ) = 0;
virtual ComparableType getType( void ) = 0;
protected:
virtual ~Comparable( void ){ } ;
protected:
virtual bool operator>( const Comparable& isLessThan ) = 0;
virtual bool operator<( const Comparable& isGreaterThan ) = 0;
virtual bool operator>=( const Comparable& isLessThanOrEqualTo ) = 0;
virtual bool operator<=( const Comparable& isGreaterThanOrEqualTo ) = 0;
virtual bool operator==( const Comparable& isEqualTo ) = 0;
virtual bool operator!=( const Comparable& isNotEqualTo ) = 0;
protected:
ComparableType mComparableType;
};
它作为以下内容的基础:
class ShaderComparable : public Comparable, public std::string
{
public:
ShaderComparable( void ) { };
ShaderComparable( const char* shaderFilename );
~ShaderComparable( void );
public:
inline std::string& getKey( void ) { return mFilename; }
inline ComparableType getType( void ) { return mComparableType; }
public:
virtual bool operator>( const ShaderComparable& isLessThan );
virtual bool operator<( const ShaderComparable& isGreaterThan );
virtual bool operator>=( const ShaderComparable& isLessThanOrEqualTo );
virtual bool operator<=( const ShaderComparable& isGreaterThanOrEqualTo );
virtual bool operator==( const ShaderComparable& isEqualTo );
virtual bool operator!=( const ShaderComparable& isNotEqualTo );
private:
inline bool isSameType( const ShaderComparable& objectToCheck ) { return mComparableType == CompType_ShaderObject; }
std::string mFilename;
};
唯一的问题是,由于某种原因,我无法重载基类中的运算符函数以接受 的类型ShaderComparable
,而不仅仅是Comparable
. 有没有解决的办法?
我的错误如下:
>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(26): error C2653: 'ShaderComparable' : is not a class or namespace name
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(26): error C2143: syntax error : missing ',' before '&'
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(33): error C2653: 'ShaderComparable' : is not a class or namespace name
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(33): error C2143: syntax error : missing ',' before '&'
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(39): error C2653: 'ShaderComparable' : is not a class or namespace name
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(39): error C2143: syntax error : missing ',' before '&'
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(44): error C2653: 'ShaderComparable' : is not a class or namespace name
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(44): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(44): error C2143: syntax error : missing ',' before '&'
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(49): error C2653: 'ShaderComparable' : is not a class or namespace name
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(49): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\programming\c++\git\escalator\engine\engine\shadercomparable.cpp(49): error C2143: syntax error : missing ',' before '&'
更新
这是它来自的源文件:
ShaderComparable::ShaderComparable( const char* shaderFilename )
: Comparable( CompType_ShaderObject ),
mFilename( shaderFilename )
{}
ShaderComparable::~ShaderComparable( void )
{
}
bool ShaderComparable::operator>( const ShaderComparable& isLessThan )
{
std::string toCompare = std::string();
if( toCompare.compare( mFilename ) > 0 )
return true;
else
return false;
}
}
bool ShaderComparable::operator<( const ShaderComparable& isGreaterThan )
{
std::string toCompare = std::string();
return true;
}
bool ShaderComparable::operator>=( const ShaderComparable& isLessThanOrEqualTo )
{
return false;
}
bool ShaderComparable::operator<=( const ShaderComparable& isGreaterThanOrEqualTo )
{
return false;
}
bool ShaderComparable::operator==( const ShaderComparable& isEqualTo )
{
return false;
}
bool ShaderComparable::operator!=( const ShaderComparable& isNotEqualTo )
{
return false;
}