This is what I have. Looks gross.
ABC::ABC(std::string newVar1,int newVar2)
{
var1=newVar1;
var2=newVar2;
}
Can this be done on the same line? Something like:
ABC::ABC(std::string newVar1,int newVar2):var1,var2
This is what I have. Looks gross.
ABC::ABC(std::string newVar1,int newVar2)
{
var1=newVar1;
var2=newVar2;
}
Can this be done on the same line? Something like:
ABC::ABC(std::string newVar1,int newVar2):var1,var2
You may do:
ABC::ABC(std::string newVar1, int newVar2) : var1(newVar1), var2(newVar2) {}
is there a more elegant way of declaring default variables in a constructor?
This would be initialization using the constructor.
You can have member-initialization as follows:
ABC::ABC(std::string newVar1, int newVar2)
: var1(newVar1)
, var2(newVar2)
{ }
Can this be done on the same line?
You can format the code above in same line.