Constructor doesn't get called?
-
Hi, I'm using the VS .net 2003 compiler. For some reason when create an instance of a class with:
ClassName instance();
the default constructor doesn't get called. If the instance was created with:ClassName instance;
It does call the default constructor; The code is pretty simple:ClassName::(void) { Init(); }
PS is there anyway to keep the forumn from interpretting my code as a smiley? :wtf: Thanks Hua-Ying
-
Hi, I'm using the VS .net 2003 compiler. For some reason when create an instance of a class with:
ClassName instance();
the default constructor doesn't get called. If the instance was created with:ClassName instance;
It does call the default constructor; The code is pretty simple:ClassName::(void) { Init(); }
PS is there anyway to keep the forumn from interpretting my code as a smiley? :wtf: Thanks Hua-Ying
ClassName instance();
This is an unfortunate problem with the weird C++ syntax. The above is not parsed as a an object construction, bur rather as the declaration of a function taking no arguments and returning a
ClassName
. Hence the problem. Just drop the()
and your compiler will be happy. See this article[^] by Herb Sutter for a more detailed explanation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]! -
Hi, I'm using the VS .net 2003 compiler. For some reason when create an instance of a class with:
ClassName instance();
the default constructor doesn't get called. If the instance was created with:ClassName instance;
It does call the default constructor; The code is pretty simple:ClassName::(void) { Init(); }
PS is there anyway to keep the forumn from interpretting my code as a smiley? :wtf: Thanks Hua-Ying
Hua-Ying Ling wrote: PS is there anyway to keep the forumn from interpretting my code as a smiley? You may insert an space between pair of characters that are interpreted as smileys. For example, inserting a space beteen a colon and a right parenthesis. This is a smiley :) This is not a smiley : ) -- jlr http://jlamas.blogspot.com/[^]
-
ClassName instance();
This is an unfortunate problem with the weird C++ syntax. The above is not parsed as a an object construction, bur rather as the declaration of a function taking no arguments and returning a
ClassName
. Hence the problem. Just drop the()
and your compiler will be happy. See this article[^] by Herb Sutter for a more detailed explanation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!LOL, I have seen that problem and never knew why it didn't work. (Not like I really thought about it). You get it in your mind that you are declaring and instance and you don't even realize you are doing a prototype. Tim Smith I'm going to patent thought. I have yet to see any prior art.