Let's say I have the following code:
struct Car{
public:
Car(){}
Car(int w, int d){
wheels = w;
doors = d;
}
private:
int wheels;
int doors;
};
int main(){
Car *cars = new Car[10];
cars[0] = {4, 4};
cars[1] = Car(4, 4);
}
Given that the structure does not allow setting the value of the wheels and doors other than using the constructor, what would be the best way to assign values ββto an array of cars? Is there a difference between the last two lines in the above code?
I am currently working on a hash table implementation for school, and the source C ++ code base has a Key-Value pair class with only the setKey method and without the setValue method. Therefore, I basically have to assign values ββto constructor calls and am not sure if there is a difference between using {} or classname (Key, Value) for assignment.
source
share