constructor

This is a discussion on constructor within the C++ Programming forums, part of the General Programming Boards category; can you call the class constructor like a normal method?...

  1. #1
    mrukok
    Guest

    constructor

    can you call the class constructor like a normal method?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    nope. Thats forbidden. constructors are called implicitly by you and explicitly by your compiler.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    mrukok
    Guest
    arg...

    how do i solve this problem then?:

    ive made a game and at the end i give the option to play again.
    if they want to play again, the values of all the member variables need resetting.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    either redesign your game loop or design your classes for your needs. A constructor makes and initialises an object. If you want to set a new value in an already existing object then you will not use a constructor but instead use either an assignment operator or an explicit SetValue() type function.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    ya, just have another function that resets all the values, and call that function when you need them to be reset ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  2. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  3. Replies: 3
    Last Post: 03-25-2006, 11:59 PM
  4. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 03:50 AM
  5. Constructor with Parameter not Firing
    By BillBoeBaggins in forum Windows Programming
    Replies: 4
    Last Post: 08-26-2004, 02:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21