내부 'CompaniesMap.h': 'CompaniesMap.cpp'에서더 적합한 사용자 정의 변환
class CompaniesMap
{
public:
...
// The companies map
map<string, CompanyP> companies;
};
typedef map<string, CompanyP>::iterator map_it;
는 :
string* CompaniesMap::displayCompaniesList() const
{
string* compList = new string[companies.size() + 1]; // We add 1 so we can start with the [1] index for simplicity
// Check if 'companies' is empty
if (companies.empty())
{
cout << "No companies in the database." << endl;
return nullptr;
}
for (map_it it = companies.begin(), int i = 1; it != companies.end(); ++it, i++)
{
cout << " " << i << ") " << it->first << endl;
compList[i] = it->first;
}
}
Visual Studio에서 다음과 같은 오류 메시지가 companies.begin()
아래에 빨간색 선을 보여줍니다 :
코드를 map_it it =
에서 map<string, CompanyP>::iterator
으로 변경하려고 시도했지만이 오류가 여전히 발생합니다.
나는 동일한 코드를 main.cpp
에 가지고 있었지만 별도의 클래스로 옮기기로 결정 했으므로 동일한 헤더를 포함하지만이 오류는 계속 표시됩니다. 내가 구축 할 때 나는이 파일에서 다른 오류를 얻을 :
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(66): error C2062: type 'int' unexpected
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(66): error C2065: 'i' : undeclared identifier
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(66): error C2143: syntax error : missing ';' before ')'
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(67): error C2143: syntax error : missing ';' before '{'
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(68): error C2065: 'i' : undeclared identifier
1>d:\asaf\c\vs\hw5\hw5\hw5\companiesmap.cpp(69): error C2065: 'i' : undeclared identifier
을이 "우리는 1 그래서 우리는 단순함에 대한 [1] 인덱스로 시작할 수 있습니다 추가 "C/C++를 프로그래밍하는 데 사용 된 모든 사람을 속일 수 있습니다. (단순함이 의심 스럽다.) –
확실하지는 않지만 ...'CompaniesMap :: displayCompaniesList()'는'const'이다. 이는 모든 클래스 멤버가 함수에서'const'를 효과적으로 의미한다는 것을 의미한다. 즉,'companies'는' 'iterator' 대신에'const_iterator'를 사용합니다. – Dialecticus
@ DieterLücking 메뉴에는 "1)", "2)"등의 접두사가있는 회사 목록이 표시됩니다. 회사가 메뉴 번호와 관련되어 있다는 것이 더 간단하지 않습니까? – PanthersFan92