Я получаю следующие ошибки:
softwarew.hh: In constructor ‘Software::Software(std::string, int):
softwarew.hh:26:45: error: class ‘Software does not have any field named ‘ptr
softwarew.hh:28:7: error: ‘ptr was not declared in this scope
softwarew.hh: In destructor ‘Software::~Software():
softwarew.hh:40:6: error: ‘ptr was not declared in this scope
Может кто-нибудь объяснить, почему я получаю эти ошибки?
Код, который вызывает ошибки:
Software(std::string name, int revision) : ptr(software_construct(name.c_str(), revision) ) {
if(!ptr) throw std::runtime_error("no software created");
}
~Software(){
if(ptr)
software_destruct(ptr);
}
private:
struct Software_s* ptr;
Ваша ошибка говорит
"class Software не имеет поля с именем ptr"
Учитывая некоторые подходящие определения Software_s
, software_construct
и software_destruct
, убедитесь, что вы положили поле внутри класса:
#ifndef SOFTWAREw_INCLUDED
#defINE SOFTWAREw_INCLUDED
class Software{
Software(std::string name, int revision)
: ptr(software_construct(name.c_str(), revision)) {
if(!ptr)
throw std::runtime_error("no software created");
}
~Software(){
if(ptr)
software_destruct(ptr);
}
private:
struct Software_s* ptr;
};
#endif