Cześć. Zrobiłem taką strukturę:
struct Variable
{
Variable(const std::string &name, void *variable);
std::string name;
void *variable = nullptr;
};
Oraz taką funkcję:
bool Scripts::foundVaraible(const std::string &variableName)
{
std::string deleted = "";
for (unsigned int i = 0; i < variableName.size(); ++i)
{
if (variableName == "int ")
{
int variable = 0; //chodzi o to
variables.push_back(Variable("d", &variable)); //i o to
}
else if(variableName == "float ")
{
}
}
}
I zgaduję że jeżeli tak to zrobię to się zmienna variable usunie i wskaźnik będzie wskazywał na nie istniejącą zmienną, ale interesuje mnie co się stanie jak zrobię to dynamicznie. Jak zrobiłem to tak:
int *x[10];
for (unsigned int i = 0; i < 10; ++i)
{
int *y = new int(0);
x[0] = y;
}
for (unsigned int i = 0; i < 10; ++i)
{
std::cout << *x[i] << " " << x[i] << std::endl; //o tu był crash
}
To wywalało crasha.