입력 할 책의 양을 입력하고 오버로드 된 연산자 ([])를 사용하는 응용 프로그램을 만들었지 만 배열을 저장할 포인터를 줄 때마다 오류가 발생합니다C++ 오버로드 연산자 []
2 인텔리과 같이 표현은 통합 또는 범위가 지정되지 않은 열거 형 라인이 있어야합니다 : (11) 칼럼 : 24 도서관 책
및
오류 1 ERR을 또는 C2440 : '초기화'는 '부호 INT'라인에 '표준 : : 문자열'에서 변환 할 수 없습니다 : (11) 칼럼 :
#include <iostream> #include <string> using namespace std; class Books{ private: string* storage; string book; public: Books(){ storage = new string[book]; } void savebooks(int iterate){ for (int i = 0; i < iterate; ++i){ cout << "Book: "; getline(cin, storage[i]); } } const string operator[](const int ref){ return storage[ref]; } ~Books(){ delete storage; } }; int main(){ //local variables int quantity; //user display cout << "Welcome to Book Storage Viewer" << endl; cout << "How many books would you like to insert: "; cin >> quantity; //instantiante Books bk; //other handle bk.savebooks(quantity); //display books cout << "These are the books you've entered" << endl; for(int i = 0; i < quantity; ++i){ cout << bk[i] << endl; } system("pause"); return 0; }
: 어쨌든 여기에 1 도서관 책
하지만 내 코드입니다 또한이 코드를 올바르게 코딩했는지, 그리고 더 이상 오류가 있으면 100 % 확실하지 않습니다. 감사합니다.
오류가 발생한 행을 나타낼 수 있습니까? 우리가 이야기하기가 어렵습니다. – Brian
'저장소 = 새 문자열 [도서]; 컴파일 오류 – gongzhitaao
여기 @BrianBi 오류 줄을 표시하고 오류가 발생한 곳인 – user3264250