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. Declaring Objects with Default Constructor

Declaring Objects with Default Constructor

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiotutorialquestion
4 Posts 3 Posters 0 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.
  • Y Offline
    Y Offline
    Yadrif
    wrote on last edited by
    #1

    Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.

    N S 2 Replies Last reply
    0
    • Y Yadrif

      Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      yadrif wrote:

      Date birthday();

      That's a declaration for function birthday that takes no parameters and returns a Date.


      Programming Blog utf8-cpp

      Y 1 Reply Last reply
      0
      • N Nemanja Trifunovic

        yadrif wrote:

        Date birthday();

        That's a declaration for function birthday that takes no parameters and returns a Date.


        Programming Blog utf8-cpp

        Y Offline
        Y Offline
        Yadrif
        wrote on last edited by
        #3

        Thanks. I get it now. I should have noticed that. Thank You.

        1 Reply Last reply
        0
        • Y Yadrif

          Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.

          S Offline
          S Offline
          Sameerkumar Namdeo
          wrote on last edited by
          #4

          using the default constructor to use the parentheses int i = int(); char c = char(); Data birthday = Data();

          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