Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Constructor doesn't get called?

Constructor doesn't get called?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studioquestion
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hyling
    wrote on last edited by
    #1

    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

    J J 2 Replies Last reply
    0
    • H hyling

      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

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      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[^]!

      T 1 Reply Last reply
      0
      • H hyling

        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

        J Offline
        J Offline
        Jose Lamas Rios
        wrote on last edited by
        #3

        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/[^]

        1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          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[^]!

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups