1
내가 멤버 함수를 배열에 다음 포인터를 구현하려고 해요
: 다음 클래스에서C++ 변환 오류
IOperand* OpCreate::createOperand(eOperandType type,
const std::string& val)
{
size_t it = 0;
OpPtrTab tab[] =
{
{Int8, &OpCreate::createInt8},
{Int16, &OpCreate::createInt16},
{Int32, &OpCreate::createInt32},
{Float, &OpCreate::createFloat},
{Double, &OpCreate::createDouble},
{Unknown, NULL}
};
while ((tab[it]).type != Unknown)
{
if ((tab[it]).type == type)
return ((tab[it]).*((tab[it]).funcPtr))(val);
it++;
}
return NULL;
}
:
class OpCreate
{
public :
struct OpPtrTab
{
const eOperandType type;
IOperand* (OpCreate::*funcPtr)(const std::string&);
};
IOperand* createOperand(eOperandType, const std::string&);
OpCreate();
~OpCreate();
private :
IOperand* createInt8(const std::string&);
IOperand* createInt16(const std::string&);
IOperand* createInt32(const std::string&);
IOperand* createFloat(const std::string&);
IOperand* createDouble(const std::string&);
};
나는 내가 잘못 한 일을 볼 수 있습니다, 하지만 여기 컴파일러 오류가 있습니다 :
OpCreate.cpp: In member function ‘IOperand* OpCreate::createOperand(eOperandType, const string&)’:
OpCreate.cpp:66:39: error: pointer to member type ‘IOperand* (OpCreate::)(const string&) {aka IOperand* (OpCreate::)(const std::basic_string<char>&)}’ incompatible with object type ‘OpCreate::OpPtrTab’
내 전화 또는 내 초기화가 프로토 타입과 일치하지 않지만 보이지 않습니다. 왜.
당신은'탭 [그것을]'객체에 멤버 함수 포인터 '탭 [그것을] .funcPtr'을 적용하지만, 가리 키지 않는 'tab [it]'객체의 멤버 함수에. 나는 당신을'this'에 적용하고 싶다고 생각합니다 :'(this -> * (tab [it] .funcPtr)) (val);'. – jogojapan
감사합니다. 효과가있었습니다. – Kernael
@ jogojapan 'Kernael'이 동의 할 수 있도록 답변으로 의견을 제안하는 것이 좋습니다. –