adresse einer konstanten temporaeren variable an funktion uebergeben <- legal ?
-
hola leute
ist folgendes laut std abgedeckt ?
class A { public: A(int x) : a_(x) { } int a_; }; int blub(const A &a) { return a.a_ * 2; } ... int d = blub(A(3));
Meep Meep
-
ja.
-
... und wenn ich das richtig verstanden habe: Das Entscheidende ist dabei dieses "const":
Meep Meep schrieb:
...
int blub( /* -> */ const /* <- */ A &a)
...
Gruß,
Simon2.
-
Nur, das das keine Adresse, sondern eine Referenz ist.
-
Braunstein schrieb:
Nur, das das keine Adresse, sondern eine Referenz ist.
Stimmt natürlich, aber mal eine Frage: Wäre das eigentlich anders bei folgendem Code ?
int blub(const A *a) { return a->a_ * 2; } ... int d = blub(&A(3));
Gruß,
Simon2.
-
Das Thema hatten wir im Prinzip schon mal:
Thema