Thread: Class constructors

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    Class constructors

    im not sure how to word this but how do i do this

    Code:
    class NM  //create class
    ...         
    
    NM nm();   //call default constructor
    
    ...   //do some stuff
    
    nm(a,b,c); //reconstruct nm with different constructor
    
    ...//do more stuff
    i guess what i want to do is make a class global, then do some stuff to find out variables that i need to initialize the class in main...

    thanks

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    ok first up, this
    Code:
    class NM  //create class
    
    NM nm();   //call default constructor
    is an error. it doesn't call the default constructor. it declares a function nm returnging an NM object.

    Quote Originally Posted by c++.prog.newbie
    i guess what i want to do is make a class global, then do some stuff to find out variables that i need to initialize the class in main...

    thanks
    well you could create the class, then set the members via set methods, but why do you want to do this? Globals are (usually) a sign of a bad design. give a bit mroe detail and we might be able to help you out.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    well, i guess they dont need to global, now that i think about i, i just need to pass them as references... and the NM nm(); was my mistake, it was just an example. I guess i shoulda put a bit more thought into what i was doing... i'm redoing some parts of the code and it required that a function had access to the class, so i thought to make it global. Ya ill just pass it as a reference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Replies: 1
    Last Post: 11-10-2002, 07:37 PM
  4. Constructors + Derived class
    By MethodMan in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2002, 05:05 PM
  5. Constructors of a class
    By casanova0o7 in forum C++ Programming
    Replies: 3
    Last Post: 01-31-2002, 03:46 PM