私はコンパイル時にこのエラーを取得しています(G ++ 4.4.6)は、次のようにC++欠落初期化子エラー
main.cpp: In function ‘int main()’:
main.cpp:27: error: expected initializer before ‘:’ token
main.cpp:33: error: expected primary-expression before ‘for’
main.cpp:33: error: expected ‘;’ before ‘for’
main.cpp:33: error: expected primary-expression before ‘for’
main.cpp:33: error: expected ‘)’ before ‘for’
main.cpp:33: error: expected initializer before ‘:’ token
main.cpp:36: error: could not convert ‘((list != 0u) ? (list->SortedList::~SortedList(), operator delete(((void*)list))) : 0)’ to ‘bool’
main.cpp:37: error: expected primary-expression before ‘return’
main.cpp:37: error: expected ‘)’ before ‘return’
私のコードは次のとおりです。可能性のソースを知っている
#include <iostream>
#include "Student.h"
#include "SortedList.h"
using namespace std;
int main() {
SortedList *list = new SortedList();
Student create[100];
int num = 100000;
for (Student &x : create) { // <--Line 27
x = new Student(num);
num += 10;
}
for (Student &x : create)
list->insert(&x);
delete list;
return 0;
}
誰もエラーは大きな助けになるでしょう。また、StudentとSortedListは、.hファイルで宣言されたオブジェクトです。あなたは、通常のfor
ループにあなたのコードを変換したり、std::for_each
か何かを使用するか、またはあなたのコンパイラをアップグレードする必要がありますので、
'-std = C++ 0x'でコンパイルしていますか? – ildjarn
-std = C++ 0xが何を意味するのかを説明することができれば、C++にはいくぶん新しかったです –
@PatMurray:遠隔地のforループ(あなたの27行目)はC++ 11の機能です。 C++ 11の機能を利用できるようにするには、コンパイラに '-std = C++ 0x'または(新しいバージョンでは-std = c + 11)を渡す必要があります。しかし、コンパイラを新しいバージョンにアップグレードすることをお勧めします。 –