cs_lalebarde
Messages postés
6
Date d'inscription
samedi 6 octobre 2007
Statut
Membre
Dernière intervention
8 octobre 2007
7 oct. 2007 à 14:38
Voici ce que je veux faire :
//sc.h
#ifndef SC_H_
#define SC_H_
#include <vector>
#include <deque>
#include <cstdlib>
#include
using namespace std;
class A {
public:
A();
A(int val_);
int show();
private:
int val;
};
typedef deque ContenerA; //gona test with conteners : vector, list, deque
#define SIZE_B 10
class B {
public:
ContenerA b;
B();
int show();
private:
static vector bMasterInit;
static bool flagInit;
};
#endif /*SC_H_*/
//sc.cpp
#include "sc.h"
int rand(int range) {
return int(double(rand())/RAND_MAX*range);
}
A::A() {};
A::A(int val_) : val(val_) {};
int A::show() {return val;}
bool B::flagInit=false;
vector B::bMasterInit(SIZE_B);
B::B() {
if (!flagInit) {
for (int i=0; ib[i].show() << ", ";
}
cout << endl;
return 0;
}
int main() {
B x, y, z;
x.show();
y.show();
z.show();
return 0;
}
When I run it, I have :
[0] = 8, [1] = 3, [2] = 7, [3] = 7, [4] = 9, [5] = 1, [6] = 3, [7] = 7, [8] = 2, [9] = 5,
[0] = 8, [1] = 3, [2] = 7, [3] = 7, [4] = 9, [5] = 1, [6] = 3, [7] = 7, [8] = 2, [9] = 5,
[0] = 8, [1] = 3, [2] = 7, [3] = 7, [4] = 9, [5] = 1, [6] = 3, [7] = 7, [8] = 2, [9] = 5,
Ca fonctionne, car j'ai provisoirement implémenté bMasterInit comme un vector.
Mais je voudrais l'implémenter comme un deque ou plus vraisemblablement comme un list. Mais je ne vois pas alors comment déclarer bMasterInit pour le faire avaler au compilateur.</cstdlib></deque></vector>