Thread: Constructors, newbie question.

  1. #1
    Registered User
    Join Date
    Jan 2002

    Constructors, newbie question.

    I'm pretty inexperienced when it comes to C++ and I have a question.

    AFAIK, constructors cannot return anything. So how can the constructor let the function making an instance of the class in question know that something has gone wrong?

    Iish, that was a mouthful. Sorry.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    The only way would be to set a flag in the class, and hope that the user checks it before trying anything. Or maybe throwing an exception, but I don't know much about that.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    That's easy. Install an error class which handles that. But what are you worried about? Bad alloc's? Programmer error? Using assert() is the way you detect programming errors early on, the only other real issue is memory allocation failure. But then, what really *can* you do about that but to bail out? Sure if you want to log something first, otherwise, just let it die - maybe the user will get a bigger harddrive then.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. Newbie question
    By wireless in forum C++ Programming
    Replies: 1
    Last Post: 02-24-2002, 05:25 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM