vector <int>
-
Hallo. Ich habe folgendes Programm, was funktioniert.
#include <iostream.h> #include <vector> vector<int> funktion () { vector<int> y; y.resize(5); y[0] = 1; y[1] = 5; y[2] = 3; y[3] = 4; y[4] = 9; return y; } int main () { vector<int> z = funktion(); // Ausgabe cout << z[0]<<endl; cout << z[1]<<endl; cout << z[2]<<endl; cout << z[3]<<endl; cout << z[4]<<endl; getchar(); return 0; }
Jetzt wollte ich es mehrere Dateien aufteilen:
- main.cpp -#include <iostream.h> #include <vector> #include "head.h" int main () { vector<int> z = funktion(); // Ausgabe cout << z[0]<<endl; cout << z[1]<<endl; cout << z[2]<<endl; cout << z[3]<<endl; cout << z[4]<<endl; getchar(); return 0; }
- header.h -
vector<int> funktion();
- funktion.cpp -
#include "head.h"vector<int> funktion () { vector<int> y; y.resize(5); y[0] = 1; y[1] = 5; y[2] = 3; y[3] = 4; y[4] = 9; return y; }
als Fehler kommt dann:
head.h ->1. Fehler in der Deklarationssyntex
head.cpp ->2. Bezeichner 'vector' mehrfach deklariert
head.h ->3. 'vector' bereits deklariert
head.cpp ->4. Fehler in der DeklarationssyntexIch arbeite mit dem Borland C++ Builder 5
Kann mir jemand sagen, was da noch falsch ist?
-
Füge mal in header.h includeguards ein undincludiere in header.h vector mittels include <vector>. Desweiteren schreibe vor den vector<int> noch std:: (also std::vector<int> )
-
ja super, danke