Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am defining a container in a x.cpp file as
vector<string> somevariable;

I am trying to use it in another y.cpp file. I declare the vector as extern in y.cpp file like
extern vector<string> somevariable;

But when I compile the program I get the errors like:
1) somevariable : identifier not found; even with argument dependent lookup
2) error C2143: syntax error : missing ';' before '<'

I have included <string>, <vector> in my files and also using namespace std;

what am I missing?
Posted
Updated 21-Dec-09 0:51am
v3

Did you include x.cpp file in your project?
Did you include the required headers in both y.cpp and x.cpp source files?
The following test:
file b.cpp
#include <vector>
#include <string>

using namespace std;

vector <string> v;

file main.cpp
#include <vector>
#include <string>
#include <iostream>

using namespace std;

extern vector<string> v;
int main()
{
  v.push_back(string("hi"));
  cout << v[0] << endl;
} 

compiles (and runs) fine.
:)
 
Share this answer
 
I think you need to declare it extern and initialise it in x.cpp. See the MSDN reference[^] for further information.

I stand corrected; Signor Pallini has the answer.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900