Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Class/Overloaded funtion help

Class/Overloaded funtion help

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questioncareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tekkie2412
    wrote on last edited by
    #1

    Im reading "teach yourself C++ in 21 days", well Ive been stuck on day 6 for about a week now. Can anyone tell me whats wrong with this source? I keep getting overloaded function errors but I really want to understand this before I move on to day 7. thanks /* Chapter 6 end of lesson program Teach yourself C++ in 21 days */ // simple program to test my knowlege of classes... // make a class that assignes and reads values using public accessors #include class Employee { public: int GetAge() const; void SetAge(int age); int GetYearsOfService() const; void SetYearsOfService(int yearsOfService) const; //Public accessors so that the variables can remain private int GetSalary() const; void SetSalary(int salary); private: int age; int yearsOfService; //Private variables int salary; }; int Employee::GetAge() { return age; } void Employee::SetAge(int age2) { age = age2; } int Employee::GetYearsOfService() { return yearsOfService; } void Employee::SetYearsOfService(int yearsOfService2) { yearsOfService = yearsOfService2 } int Employee::GetSalary() { return salary; } void Employee::SetSalary(int salary2) { salary = salary2; } void main() { int age2, yearsOfService2, salary2; Employee Matt; //define 2 objects of class employee Employee Max; Matt.SetAge(21); Max.SetAge(35); Matt.SetYearsOfService(2); //assign values to the 2 objects Max.SetYearsOfService(6); Matt.SetSalary(20000); Max.SetSalary(34600); cout<<"Matts age is : "; cout<

    M 1 Reply Last reply
    0
    • T tekkie2412

      Im reading "teach yourself C++ in 21 days", well Ive been stuck on day 6 for about a week now. Can anyone tell me whats wrong with this source? I keep getting overloaded function errors but I really want to understand this before I move on to day 7. thanks /* Chapter 6 end of lesson program Teach yourself C++ in 21 days */ // simple program to test my knowlege of classes... // make a class that assignes and reads values using public accessors #include class Employee { public: int GetAge() const; void SetAge(int age); int GetYearsOfService() const; void SetYearsOfService(int yearsOfService) const; //Public accessors so that the variables can remain private int GetSalary() const; void SetSalary(int salary); private: int age; int yearsOfService; //Private variables int salary; }; int Employee::GetAge() { return age; } void Employee::SetAge(int age2) { age = age2; } int Employee::GetYearsOfService() { return yearsOfService; } void Employee::SetYearsOfService(int yearsOfService2) { yearsOfService = yearsOfService2 } int Employee::GetSalary() { return salary; } void Employee::SetSalary(int salary2) { salary = salary2; } void main() { int age2, yearsOfService2, salary2; Employee Matt; //define 2 objects of class employee Employee Max; Matt.SetAge(21); Max.SetAge(35); Matt.SetYearsOfService(2); //assign values to the 2 objects Max.SetYearsOfService(6); Matt.SetSalary(20000); Max.SetSalary(34600); cout<<"Matts age is : "; cout<

      M Offline
      M Offline
      Michael Gunlock
      wrote on last edited by
      #2
      1. Overloaded function errors due to missing const qualifier in function definitions When you declare a member function constant, the const qualifier is also required in the function definition (and declaration). For example, class Employee { ... int GetAge() const; ... }; int Employee::GetAge() const{ return age; } 2) Don't declare SetYearsOfService() as a constant member function (leave off the const at the end) 3) Missing ; in SetYearsOfService() void Employee::SetYearsOfService(int YearsOfService2) { yearsOfService=yearsOfService2; }
      T 1 Reply Last reply
      0
      • M Michael Gunlock
        1. Overloaded function errors due to missing const qualifier in function definitions When you declare a member function constant, the const qualifier is also required in the function definition (and declaration). For example, class Employee { ... int GetAge() const; ... }; int Employee::GetAge() const{ return age; } 2) Don't declare SetYearsOfService() as a constant member function (leave off the const at the end) 3) Missing ; in SetYearsOfService() void Employee::SetYearsOfService(int YearsOfService2) { yearsOfService=yearsOfService2; }
        T Offline
        T Offline
        tekkie2412
        wrote on last edited by
        #3

        thanks, I feel the headache going away already :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups