| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Passing vector by reference huge problems
I am not able to pass vector by reference if I read it from a txt file and populate it. What is wrong with the code here? Please help as I am stuck with this problem for 1 day.
#include <iostream> #include <fstream> #include <vector> #include <math.h> void signedDistanceTransform2D(vector<int> &iContour); using namespace std; int main() { fstream infile("crack_index.txt"); vector<int> iContour(100); if(!infile) { cout<<"Error opening output file"<<endl; system("pause"); return -1; } else { int C_point=0; // checking for the current point while(infile>> C_point) { //putting the initial crack points in the vector iContour.push_back(C_point); } signedDistanceTransform2D(iContour); return 0; } } void signedDistanceTransform2D(vector<int> &iContour) {} It is throwing errors like which is bizarre \Users\vivek\Documents\main.cpp(7) : error C2065: 'vector' : undeclared identifier C:\Users\vivek\Documents\main.cpp(7) : error C2062: type 'int' unexpected C:\Users\vivek\Documents\main.cpp(13) : error C2872: 'vector' : ambiguous symbol C:\Users\vivek\Documents\main.cpp(13) : error C2872: 'vector' : ambiguous symbol C:\Users\vivek\Documents\main.cpp(13) : error C2062: type 'int' unexpected C:\Users\vivek\Documents\main.cpp(25) : error C2065: 'iContour' : undeclared identifier C:\Users\vivek\Documents\main.cpp(25) : error C2228: left of '.push_back' must have class/struct/union type C:\Users\vivek\Documents\main.cpp(32) : error C2065: 'signedDistanceTransform2D' : undeclared identifier C:\Users\vivek\Documents\main.cpp(43) : error C2872: 'vector' : ambiguous symbol C:\Users\vivek\Documents\main.cpp(43) : error C2872: 'vector' : ambiguous symbol C:\Users\vivek\Documents\main.cpp(43) : error C2062: type 'int' unexpected C:\Users\vivek\Documents\main.cpp(43) : error C2143: syntax error : missing ';' before '{' C:\Users\vivek\Documents\main.cpp(43) : error C2447: missing function header (old-style formal list?) Error executing cl.exe. main.obj - 13 error(s), 0 warning(s) |
|
#2
|
||||
|
||||
|
Swap these two lines:
void signedDistanceTransform2D(vector<int> &iContour); using namespace std; You're using vector<int> before the using namespace directive. That means vector is still only known as std::vector.
__________________
There is no such thing as C/C++, you either program C or C++ |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Passing vector by reference huge problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|