Witam,
Próbując "zwiększyć" tablicę dynamiczną typu String program się kończy, ale gdy zmienię typ na int wszystko gra.
#include <iostream>
#include <string>
using namespace std;
void fill(string* wsk, int& size);
string *expandTable(string* logs, int &size);
int main()
{
int size=5;
int logNum = 5;
int &s = size;
string *logs = new string [s];
cout << "Size: " << s << endl;
fill(logs, s);
logs = expandTable(logs, s);
cout << "Size: " << s << endl;
fill(logs, s);
return 0;
}
string *expandTable(string* logs, int& size){
size *= 2;
string *n_logs = new string [size];
for (int i=0; i<size; i++){
n_logs[i] = logs[i];
}
delete [] logs;
return n_logs;
}
void fill(string* wsk, int& size){
for (int i=0; i<size; i++){
cin >> wsk[i];
}
}
Dlaczego tak jest?