Thread: class definition Q

  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,005
    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,005
    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, 11:26 AM
  2. help with class varialbe definition..
    By smartalco in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2006, 03:37 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Class Definition?
    By Jamina in forum C++ Programming
    Replies: 4
    Last Post: 08-07-2003, 11:12 PM