Is it possible to access a vector in cpp file that belongs to another cpp file?

I'm trying to access a vector of movies from my movie.cpp file and use it in my client file. how would i go about doing that?
You need to make a movie.h file and declare your vector in that:
1
2
3
4
5
6
7
8
9
10
#ifndef _MOVIE_H_
#define _MOVIE_H_

#include <vector>
#include <string>

// declare the vector from your movie.cpp file as "extern" here
extern std::vector<std::string> movilist;

#endif // _MOVIE_H_ 

Then you need to #include "movie.h" in any file that wants to access the vector.
Last edited on
Topic archived. No new replies allowed.