Vector defined static
I dont have any ideea which vector defined static can i use for this class, and i dont know how to define it.
Can you help me ? Thanks !
class User
{
private:
const int Id_user;
char* Name_user;
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <vector>
using namespace std;
class User
{
private:
const int Id_user;
char* Name_user;
static vector<int> MyVector;//could be static const vector<int> as well if required;
User();
};
std::vector<int> MakeVector()
{
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
return v;
}
vector<int> User::MyVector = MakeVector();
//or C++11 does it more suuccintly: vector<int> User::MyVector = {1, 2, 3, 4};
|
Topic archived. No new replies allowed.