I know that declaring variables like this int a = 10, b = 15, c = 20
is possible and it's ok, but is it possible in any program in c++ programming language, to declare variables like this int a, b, c = 10, 15, 20
where a
need to be 10
, b
need to be 15
and c
to be 20
.
Is this possible and is it right way to declare variables like this in c++?
EDIT: Is it possible with the overloading operator =
?
The compiler will issue an error for such declarations
int a, b, c = 10, 15, 20;
The only idea that comes to my head is the following :)
int a, b, c = ( a = 10, b = 15, 20 );
Or you could make these names data members of a structure
struct { int a, b, c; } s = { 10, 20, 30 };
EDIT: Is it possible with the overloading operator =?
There is not used the copy asssignment operator. It is a declaration. The copy assignment operator is used with objects that are already defined.:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With