0

Hi list,

Three functions use the following items vector. Where/how should i put the vector to make this possible ?
Any reference to related sources will be appreciated.

vector< vector<int> > items ( 6, vector<int> ( 6 ) );

P.S I tried to make it static but it gave error unfortunately .

Edited by cangan: n/a

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by cangan
0

just declare it in a class and mention your three functions in the class
make an object in main and access the data

0

Hi,
i am new in std::vector/cli::vector class. I dont know which one is more suitable for me. So i just want to see if it works in a single form application. Therefore its enought to make it global. Is this possible?
:?:

Edited by cangan: n/a

0

Globals are EVIL. Period.
You have two ways:
1. declare the vector inside main() and pass a pointer (this is more C-way)

void foo(vector<vector<int> >* items){
};
void bar(vector<vector<int> >* items){
};
void foobar(vector<vector<int> >* items){
};

void main(){
	vector< vector<int> > items ( 6, vector<int> ( 6 ) );
	foo(&items);
	bar(&items;
	foobar(&items);
}

2. make a simple class (C++-way)

class foobar{
public:
	vector< vector<int> > items ( 6, vector<int> ( 6 ) );
	void foo(vector<vector<int> >* items){
	};
	void bar(vector<vector<int> >* items){
	};
	void foobar(vector<vector<int> >* items){
	};
};

void main(){
	foobar foo;
	foo.items[0][0]=5;
	foo.foo();
	foo.bar();
	foo.foobar();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.