私は間違って何をしているのかわかりません。これは私の初めての.cppファイルの分離とテンプレートとベクトルの使い方です。私はこれらの2つのエラーが発生し続ける:エラーC2143:構文エラー: '、'の前に '<'が見つかりません。注:C++コンパイラは、どのような種類を知っていないので、あなたがこれを行うには、明示的なインスタンス化を必要とするデフォルト-INTテンプレートとベクトルのエラー
main.cppに
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void write_vector(const vector<T>& V);
int main()
{
int n;
int value;
vector<int> V;
cout << "Enter n: ";
cin >> n;
cout << "Enter " << n << " integer values: ";
while(V.size() < n && cin >> value){
V.push_back(value);
}
write_vector(V);
return 0;
}
writeVector.cpp
template <typename T>
void write_vector(const vector<T> &V)
{
for(int i=0; i < V.size(); i++)
cout << V[i] << " ";
}
エラーの行は何ですか? –
writeVector.cppはどこにインクルードしますか?テンプレートはオブジェクトファイルとは別にコンパイルできないため、最終的にmain.cppにインクルードする必要があります。どのラインでエラーが表示されますか? – dimba