Wow, what compiler is that? I would have expected a compiler warning for the unused function (and the unused variable) 
-
-
-
There is no unused variable, and the function is only declared, never defined. It's standard clang.
-
But what about 'ping', isn't that a instance of type Pinger that is unused until it is out of scope?
-
This is just a boiled down version of the problem. In the original code, ping was used later
-
Arrggghh, OK... Coding reality sucks
Ende der Unterhaltung
Neue Unterhaltung -
-
-
Took me a minute
-
Took me two hours.
-
But you did not have the hints you gave. I know these days. They feel so very productive. Not.
Ende der Unterhaltung
Neue Unterhaltung -
-
-
In-body function declarations are indeed an odd artifact. One reason why we should move to auto-style variable declations in post-C++11 code: auto pc = PingController{Pinger};
-
Yeah, curly braces helped me finally debug it. Will now use them everywhere where 11 is acceptable.
- 1 weitere Antwort
Neue Unterhaltung -
-
-
I still don't get it. What I would expect is that "Pinger" in the second line is interpreted as a constructor. So a temporal object is passed to pc instead of the intended "ping" object. If accessed via "&", the compiler would warn. Not if just a function is called.
-
But it isn't. Compiler thinks it's a function declaration for a function taking a (unnamed) Pinger object returning a PingerController object, called pc
-
Ok, I got your point, thanks for the explanation. I have to try this with some compilers tomorrow.
Ende der Unterhaltung
Neue Unterhaltung -
-
-
What did you expect to happen? Shirley you wanted to pass ping to the constructor, not Pinger?
-
Yes. And I expect the compiler to at least warn me that an unused function declaration inside a function might not be what I intended. From c++11 I would be able to use "PingerController pc{Pinger};" which would have helped find the brain fart quicker.
-
Yes, a warning would be good. The “if it could be a function declaration then it is” has been there since the earliest days of C++ or even C-with-classes — ever since constructors with arguments were invented.
Ende der Unterhaltung
Neue Unterhaltung -
-
-
That‘s one of the first things every C++ developer learns: https://en.m.wikipedia.org/wiki/Most_vexing_parse …
-
You was faster: I was searching for a nice uniform initialization explanation ;-)
Ende der Unterhaltung
Neue Unterhaltung -
-
-
Thus ist why since C++-11 it IS reccomended to call the c-tors via curly braces. Like: PingController pc{Pinger};
Danke! Twitter wird dies nutzen, um deine Timeline zu verbessern. Rückgängig machenRückgängig machen
-
Das Laden scheint etwas zu dauern.
Twitter ist möglicherweise überlastet oder hat einen vorübergehenden Schluckauf. Probiere es erneut oder besuche Twitter Status für weitere Informationen.