前提・実現したいこと
以下のようなソースコードをコンパイルする際に「missing typename prior to dependent type name」というエラーが、「vector<T,Allocator>::const_iterator の箇所を指して出てしまいます。
このコンパイルエラーを修正する方法を知りたいです。
発生している問題・エラーメッセージ
vector<T,Allocator>::const_iterator の箇所に「missing typename prior to dependent type name」というエラーがでる。
該当のソースコード
c++
1// ベクトルの全要素の表示(反復子) 2 3#include <string> 4#include <vector> 5#include <iostream> 6 7using namespace std; 8 9//--- ベクトルvの全要素を{}で囲んで順に表示 --// 10template <class T, class Allocator> 11void print_vector(vector<T, Allocator>& v) 12{ 13 cout << "{ "; 14 for (vector<T, Allocator>::const_iterator i = v.begin(); i != v.end(); i++) 15 cout << *i << ' '; 16 cout << '}'; 17} 18 19int main() 20{ 21 int a[] = {1, 2, 3, 4, 5}; 22 vector<int> x(a, a + sizeof(a) / sizeof(a[0])); 23 24 double b[] = {3.5, 7.3, 2.2, 9.9}; 25 vector<double> y(b, b + sizeof(b) / sizeof(b[0])); 26 27 string c[] = {"abc", "WXYZ", "123456"}; 28 vector<string> z(c, c + sizeof(c) / sizeof(c[0])); 29 30 cout << "x = "; print_vector(x); cout << '\n'; 31 cout << "y = "; print_vector(y); cout << '\n'; 32 cout << "z = "; print_vector(z); cout << '\n'; 33}
試したこと
コンパイルをc++11,14,17でやってみましたがいずれもうまくいきませんでした。
補足情報(FW/ツールのバージョンなど)
g++を使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/30 09:57