Thread: help, what is wron in this code?

  1. #1
    Registered User
    Join Date
    Jun 2003

    help, what is wron in this code?

    i created this class:

    class Surgery
    double cost();

    I am then using it in this line:


    but I get this error:

    g:\hospital\hospital.cpp(22) : error C2275: 'Surgery' : illegal use of this type as an expression

    What is the problem? I have spent hours and dont see the problem!!!!!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    First off, it's bad design. Second off, you should be making an actual instance of the function, or ... I believe you can make it a static function and have it work. I'd have to look it up to be sure. (I never use C++.)

    There's a way to do it, but you can't just make up a class definition and use functions from it with no instance of the class (unless they're static, or whatever the keyword is I'm looking for).

    That being said:
    class Surg
            double cost( ) { return SOMETHING_HERE; }
    Surg instance;
    foo[bar].addCost( instance.cost( ) );
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    You need to make an instance of your class.
    Surgery s;
    Detailed understanding of language features - even of all features of a language - cannot compensate for lack of an overall view of the language and the fundamental techniques for using it. - Bjarne Stroustrup

  4. #4
    Registered User
    Join Date
    Jun 2003
    thank u guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM