Thread: class method inside cout fails

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    4

    class method inside cout fails

    I created a class and when trying to print the result of a class method to the console my compiler says
    Illegal operand types: The operands are of the wrong type, casting the operands to a different type.
    The line it chokes on looks like this:

    Code:
    cout << "Your cat is " << mycat.getAge << " years old.";
    This is where I am stumped. mycat is an instance of the class cat. The method getAge returns an int, so I can't see any reason for this peice of code not to work.

    Here is the getAge method.

    Code:
    int cat::getAge(){
    return age;
    }
    I'm new to C++, haveing an already solid grasp of C, trying to migrate towards C++.

    Can anyone please lend a hand.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    change to:

    Code:
    cout << "Your cat is " << mycat.getAge() << " years old.";
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    4

    Thanks

    I made your change and it worked flawlesly. Im almost embarased I overlooked something so simple. I will remember to use parenthisies when calling methods from now on. Big thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. inline templated class method as standalone function in namespace
    By monikersupreme in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2008, 11:38 AM
  3. Calling a Method from Another Class...
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 02-02-2006, 06:31 PM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM