class definition Q

This is a discussion on class definition Q within the C++ Programming forums, part of the General Programming Boards category; I am trying to constuct a class that will represent an employee. I believe my declaration matches the definition of ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    12

    class definition Q

    I am trying to constuct a class that will represent an employee. I believe my declaration matches the definition of the constructor. Why am I getting the below errors? why would they be invalid function declarations?

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    //class declaration
     
    class Employee
    {
     private:
       int idNum;
       float payRate;
       int maxHours;
     public:
       Employee (int = 45, float = 9.00, int = 40);
       void changeData (int, float, int);
       void displayData (int, float, int);
    };
     
    //class implementation section
    Employee : : Employee (int id, float rate, int max) //unqualified-id before':' token
    {
      idNum = id;
      payrate = rate;
      maxhours = max;
    }
     
    void Employee : : changeData (int id, float rate, int max) //invalid function declaration
    {                                                                      
      idNum = id;
      payRate = rate;
      maxHours = max;
      
      return;
    }
     
    void Employee : : displayData()   ////invalid function declaration
    {
      cout<< "The employee ID is ";
      cout<<  idNum  << '/'
          << "The employee pay is ";
    	  <<  payRate << '/'
    	  << "The employee maximum hours are ";
    	  <<  maxHours << '/'
    	  << endl;
         
    return;

  2. #2
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    I am not 100% sure, but try taking the space out from between the two colons... '::' instead of ': :'

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    12
    yeah, I already tried this and in numerous ways! lol
    tks!!

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    12
    ok, just tried it again to double check myself and I now have 6 errors instead of 3...so, I am sure that is not the problem...

  5. #5
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    Everything else looks ok, What other errors did it bring up?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    The language is case-sensitive: payrate is not the same as payRate, maxhours is not the same as maxHours.

    Function signatures are important:
    Code:
       void displayData (int, float, int);
    does not match
    Code:
    void Employee :: displayData()   ////invalid function declaration
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    Dang, I must need some sleep... did not even see that myself.....

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    And if you're going to break things into multiple lines, don't prematurely end the lines.
    Code:
    void Employee :: displayData(int idNum, float payRate, int maxHours)
    {
       cout<< "The employee ID is ";
       cout<<  idNum  << '/'
       << "The employee pay is ";
       <<  payRate << '/'
       << "The employee maximum hours are ";
       <<  maxHours << '/'
       << endl;
    
       return;     
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    12
    yeah, it 'tis a bit late....
    well I changed the case sensitive items (can't believe I missed those) and I will work on the functions. Back to more reading! Thanks !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class definition error
    By rahulsk1947 in forum C++ Programming
    Replies: 4
    Last Post: 05-16-2009, 12:26 PM
  2. help with class varialbe definition..
    By smartalco in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2006, 04:37 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Class Definition?
    By Jamina in forum C++ Programming
    Replies: 4
    Last Post: 08-08-2003, 12:12 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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