C++로 개체를 만드는 데 문제가 있습니다. Instruction이라는 클래스를 만들고 새로운 인스턴스를 만들려고하는데 컴파일러 오류가 발생합니다.C++ new 연산자입니다. 새 인스턴스 만들기
클래스 코드 :
Instruction* inst;
inst = new Instruction("instruction33", 33);
나는 다음과 같은 컴파일러 오류를 얻을 :
functions.h:70: error: no matching function for call to ‘operator new(unsigned int, std::string&, int&)’
/usr/include/c++/4.3/new:95: note: candidates are: void* operator new(size_t)
/usr/include/c++/4.3/new:99: note: void* operator new(size_t, const std::nothrow_t&)
/usr/include/c++/4.3/new:105: note: void* operator new(size_t, void*)
너희들이 올
class Instruction{
protected:
string name;
int value;
public:
Instruction(string _name, int _value);
~Instruction();
void setName(string _name);
void setValue(int _value);
string getName();
int getValue();
virtual void execute();
};
//constructor
inline Instruction::Instruction(string _name, int _value){
name = _name;
value = _value;
}
//destructor
inline Instruction::~Instruction(){
//name = "";
//value = 0;
}
inline void Instruction::setName(string _name){
name = _name;
}
inline void Instruction::setValue(int _value){
value = _value;
}
inline string Instruction::getName(){
return name;
}
int Instruction::getValue(){
return value;
}
inline void Instruction::execute(){
cout << "still have to implement";
}
이것은 내가 새 개체를 만들려고하는 방법이다 . 붙여 넣은 코드와 아무 상관이없는 사실
list <Instruction> instList; //#include <list> is in the file
완벽하게 컴파일됩니다. – Xinus
코드에 문제가있는 부분을 추가했습니다. 명령어 목록에 명령어를 추가하려고하면 발생합니다. – user69514
'g ++ '로 컴파일 중입니까? 나는이 코드를'gcc'로 컴파일하려했는데 비슷한 오류가있었습니다. – hbw