다음 코드는 Boost에서 가져 와서 프로젝트에 단순화했습니다. 완전한 코드를 붙여 넣기 위해 제 어필을 받아주세요. 제 질문에 쉽게 대답 할 수 있도록 해드립니다. VS 2008에서 다음 코드를 컴파일하는 동안 followoing 오류가 발생합니다. 내가 addOptions을 기대하고용어가 C++의 함수로 평가되지 않았습니다.
error C2064: term does not evaluate to a function taking 3 arguments
은 하나가 버그를 발견하시기 바랍니다 수있는 세 가지 인수하지만 안될와 기능 연산자를 호출 OptionsInit 객체를 retruns. 미리 감사드립니다.
namespace MyInfrastructure
{
namespace Internal
{
class OptionDescrp;
class OptionsInit;
}
class OptionsCollection
{
public:
OptionsCollection(std::string optCollName);
Internal::OptionsInit addOptions();
private:
// avoid copying and assignment.
// Prohibit copy
OptionsCollection(const OptionsCollection&);
OptionsCollection& operator = (const OptionsCollection&);
void add(Internal::OptionDescrp* desc) {m_options.push_back(desc);}
std::vector<Internal::OptionDescrp* > m_options;
std::string m_optCollName;
friend class Internal::OptionsInit;
};
}
////////////
#include <string>
#include <vector>
#include <assert.h>
#include "PrgmOptions.h"
namespace MyInfrastructure
{
namespace Internal
{
class OptionDescrp
{
public:
OptionDescrp(std::string pcOptname, std::string description, bool isOptValueReq);
virtual ~OptionDescrp(){ };
private:
std::string m_shortName; // option short name.
std::string m_longName; // option long name.
std::string m_description;// option description.
};
class OptionsInit
{
public:
OptionsInit(OptionsCollection* coll){ owner = coll; }
OptionsInit& operator()(std::string name, std::string description, bool isOptValReq);
private:
OptionsCollection* owner;
};
}
/////
namespace MyInfrastructure
{
OptionsCollection::OptionsCollection(std::string optCollName) : m_optCollName(optCollName) {}
Internal::OptionsInit OptionsCollection::addOptions()
{
return Internal::OptionsInit(this);
}
}
namespace MyInfrastructure
{
namespace Internal
{
// Class Options description definitions.
OptionDescrp::OptionDescrp(std::string pcOptname, std::string description, bool isOptValueReq)
: m_description(description)
{
std::string name(pcOptname);
std::string::size_type n = name.find(',');
if (n != std::string::npos)
{
assert(n == name.size()-2);
m_longName = name.substr(0, n);
m_shortName = '-' + name.substr(n+1,1);
}
else
{
m_longName = name;
}
}
// Class Options Init definitions.
OptionsInit& OptionsInit::operator()(std::string name, std::string description, bool isOptValReq)
{
OptionDescrp* opt = new OptionDescrp(name, description, isOptValReq);
owner->add(opt);
return *this;
}
}
}
//////
int main(void)
{
MyInfrastructure::OptionsCollection desc("myoptions");
**desc.addOptions()("help", "produce help message", false); // error is thrown here**
return 0;
}
코드 예제가 불완전합니다. "/////"줄 앞에 닫는 중괄호가 없습니다. 수정 후 #include #include 시작 부분에 코드를 추가하면 MSVC2008 (2009 버전은 존재하지 않음) 및 GCC에서 정상적으로 컴파일됩니다. –
zeuxcg
먼저, 오류 메시지가 줄 번호와 함께 제공된 것 같지만 표시된 줄이 표시되지 않습니다. 오류가 발생한 행을 지적하십시오. 또한 VS 2009를 썼습니다. VS 2008을 의미합니까? –
여전히 오류가 발생하고 있습니다. VS2008을 사용하고 있습니다. – venkysmarty