"Expected undefined-id" Error Message

This is a discussion on "Expected undefined-id" Error Message within the C++ Programming forums, part of the General Programming Boards category; Ok, I just switched from C to C++, so please bear with me... I am writing a simple code to ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    "Expected undefined-id" Error Message

    Ok, I just switched from C to C++, so please bear with me...

    I am writing a simple code to make sure I understand classes, and am getting the error message:

    Code:
    error: expected unqualified-id before âintâ
    what am I doing wrong? Here's the full code:

    Code:
    #include <iostream>
    
    using namespace std;
    
    class firstclass
    {
    public:
        firstclass();
        int sum( int x, int y );
        ~firstclass();
    };
    
    firstclass::firstclass()
    {
        int z = 0;
    }
    
    firstclass::int sum( int x, int y)
    {
        z = x + y;
        return z;
    }
    
    firstclass::~firstclass()
    {
    }
    
    int main()
    {
        firstclass math;
        int a = 0;
        int b = 0;
        cout<<"Enter two numbers: First:  ";
        cin>> a ;  
        cout<<"\nSecond";
        cin>> b ;
        cout<<"The sum is"<<math.sum( a, b )<<"";
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Writing a member function doesn't look like
    Code:
    firstclass::int sum( int x, int y)
    but like
    Code:
    int firstclass::sum( int x, int y)
    (I.e., the qualifier is on the name, not the return type.)

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    2
    thank you it works perfectly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  4. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

Tags for this Thread


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