I created a class Elevator with the public, private and protected variables. Also, I wrote some methods. Now a question how can I simplify these lines of code with objects announcement.
int main()
{
Elevator ElevatorObject("NAME", 2, 3, 4, 5);
ElevatorObject.get_name();
ElevatorObject.get_loadCapacity();
ElevatorObject.get_MotorPower();
ElevatorObject.get_height();
ElevatorObject.get_witdth();
Elevator ElevatorObject1("NONAME", 5, 4, 3, 2);
ElevatorObject1.get_name();
ElevatorObject1.get_loadCapacity();
ElevatorObject1.get_MotorPower();
ElevatorObject1.get_height();
ElevatorObject1.get_witdth();
system("pause");
return 0;
}
I am thinking to put all needed names of objects into a string array and then realize it in a loop. But then there will be the same values in object parameters.
Like this.
string ObjectName[3] = { "ElevatorObject1", "ElevatorObject2", "ElevatorObject3" };
int main()
{
string ObjectName[3] = { "ElevatorObject1", "ElevatorObject2", "ElevatorObject3" };
for (int i = 0; i < 3; i++)
{
Elevator ObjectName[i]("NEMA", 2, 3, 4, 5);
ObjectName[i].get_name();
ObjectName[i].get_loadCapacity();
ObjectName[i].get_MotorPower();
ObjectName[i].get_height();
ObjectName[i].get_witdth();
}
system("pause");
return 0;
}
There is an error "C2131 the expression must have a constant value". Maybe I made a mistake somewhere...
Elevator ObjectName[i]("NEMA", 2, 3, 4, 5);this means you are trying to create a new array each loop of sizeiElevatorObject.get_name();is strange. do you meanprint_name(),input_name()?