The code is as follow :
The Code :
#include <iostream>
using namespace std;
class pub
{
string name;
public:
pub(string name):name(name){} //Constructor
void getName(string name){this->name = name;}
string returnName(void){return name;}
};
int main(void)
{
pub * p = new pub[5]; //Error-prone statement.
//Ignore for not having "delete" statement
return 0;
}
The Question :
1.) In this case , is there any method for me to pass value to each dynamic memory I've allocated , or is it I have to set a default value to the constructor's argument in order to circumvent this problem ?
Thank you !