Je vais avoir des problèmes pour obtenir que cela fonctionne,de coulée void * à un tableau d'objets en C++
class A {
public:
A(int n) {
a = n;
}
int getA() {
return a;
}
private:
int a;
};
int main(){
A* a[3];
A* b[3];
for (int i = 0; i < 3; ++i) {
a[i] = new A(i + 1);
}
void * pointer = a;
b = (A* [])pointer; // DOESNT WORK Apparently ISO C++ forbids casting to an array type ‘A* []’.
b = static_cast<A*[]>(pointer); // DOESN'T WORK invalid static_cast from type ‘void*’ to type ‘A* []’
return 0;
}
Et je ne peux pas utiliser des types génériques pour ce que je dois.
Merci d'avance.
La variable 'b' est un tableau de 3 pointeurs. Pourquoi voulez-vous jeter un pointeur vide? – Arun