How to make a vector structure globaly ?

We are developing a C++ project with 10 cpp files and 3 header files.We are declared array structure of 3 integer varibles globaly in header file and using in some files and where arrays are updated ,re-adjusted in some cpp files and use in another files.Project is running fine but we wish to use vector structure because dynamic allocation ,easy resize.

How to replace array structure to vector structure ?
How to make a vector structure globaly ?

please help us .....

Thanks
Rajeev
Put the vector in a global area, then declare it as extern in all the other files that need to use it.

Although it would probably be better just to pass it around as a function parameter or something. If you have a bunch of globals, throw them all into a structure and pass that around (or at least try to combine the relevant variables).
// header.h
1
2
3
4
5
6
7
8
#ifndef _HEADER_H
#define _HEADER_H

#include <vector>

extern std::vector<int> globalvec;

#endif 



// header.cpp
1
2
3
#include "header.h"

std::vector<int> globalvec;




// file1.cpp
1
2
3
4
5
6
#include "header.h"

void func1()
{
	globalvec.push_back(1);
}


// file2.cpp
1
2
3
4
5
6
#include "header.h"

void func2()
{
	globalvec.push_back(2);
}

Topic archived. No new replies allowed.