C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2009, 05:06 PM   #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 )<<"";
}
FlyingShoes12 is offline   Reply With Quote
Old 11-03-2009, 05:15 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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.)
tabstop is offline   Reply With Quote
Old 11-03-2009, 08:55 PM   #3
Registered User
 
Join Date: Jun 2009
Posts: 2
thank you it works perfectly
FlyingShoes is offline   Reply With Quote
Reply

Tags
error

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined Reference Compiling Error AlakaAlaki C++ Programming 1 06-27-2008 11:45 AM
C OpenGL Compiler Error? Matt3000 C Programming 12 07-07-2006 04:42 PM
c++ linking problem for x11 kron Linux Programming 1 11-19-2004 10:18 AM
Problem with OpenGL tutorial 2Biaz Windows Programming 18 09-16-2004 11:02 AM
qt help Unregistered Linux Programming 1 04-20-2002 09:51 AM


All times are GMT -6. The time now is 10:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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