入力したい本の量を入力し、オーバーロードされた演算子 ([]) を使用するアプリケーションを作成しましたが、配列を格納するためのポインターを与えるたびに、次のようなエラーが発生します。
2 IntelliSense: 式には整数型またはスコープなしの列挙型が必要です。行:11 列:24 図書館の本
と
エラー 1 エラー C2440: 'initializing' : 'std::string' から 'unsigned int' に変換できません 行:11 列:1 図書館の本
とにかくここに私のコードがあります:
#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;
}
また、これを正しくコーディングしたかどうかも 100% 確信が持てません。エラーが発生した場合は、教えていただき、ありがとうございます。