먼저이 질문이 내 첫 번째 stackoverflow 질문임을 지적해야하므로 나와 함께 부담하십시오.오버로드 된 함수 모호성
C++에서 함수 오버로드 중 일부 문제가 있습니다. 나는 다음과 같은 프로토 타입으로 함수를 만들려고 해요 :
void push_at_command(std::string, std::vector<std::string>, int);
void push_at_command(std::string, std::vector<std::string>, std::vector<std::string>, int);
void push_at_command(std::string, std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, int);
void push_at_command(std::string, std::vector<std::string>, bool, int);
내가 원래 마지막 과부하 (부울로 한) 대신 문자열 벡터의 부스트 :: 정규식을 수용하기를 원했다;
void push_at_command(std::string, boost::regex, int);
하지만, 그래서 그냥 빨리 내가 플래그를 적용하고 정규식을 저장하는 벡터의 첫 번째 요소를 사용하여 프로토 타입을 추가 거라고 생각 '작업'코드를 얻을 수 ... 모호성 오류로 실행 문자열,하지만 나는 비슷한 문제로 부울을 실행하는 것 같습니다.
이
내가 이러한 다양한 오버로드를 호출하기 위해 노력하고있어 방법은 다음과 같습니다push_at_command(
"AT?S",
boost::assign::list_of("(\\d{3}.\\d{3})"),
true,
0);
push_at_command(
"AT?S",
boost::assign::list_of("L11")("L12"),
0);
push_at_command(
"AT?S",
boost::assign::list_of("L11"),
boost::assign::list_of("L21")("L22"),
0);
을 그리고 이것은 내가지고있어 오류입니다 :
error: call of overloaded ‘push_at_command(const char [5], boost::assign_detail::generic_list<char [4]>, boost::assign_detail::generic_list<char [4]>, int)’ is ambiguous
note: candidates are:
note: void push_at_command(std::string, std::vector<std::basic_string<char> >, std::vector<std::basic_string<char> >, int)
note: void push_at_command(std::string, std::vector<std::basic_string<char> >, bool, int)
... 세 번째 기능 관련 요구.
그냥 bool로 오버로드를 추가하거나 문자열 벡터를 regex로 변경하기 전에 아무런 문제가 없습니다.
나는이 문제가 나와 관련이 있다고 가정하고 boost :: assign 함수를 호출하고, 필자는 그럴 필요가 없다는 것을 알고 있지만 실제로는 '한 줄'함수 호출이 필요하다. ... C++을 처음 접했을 때 어떤 조언도 환영합니다.
감사
개인적인 팁 : 구문 과부하를 피한다면 당신의 삶은 더 행복해 질 것입니다. –
조언을 주셔서 감사합니다, 나는 당신이 옳을 수도 있다고 생각합니다! –