pointersss...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 1
Reputation: armen_shlang is an unknown quantity at this point 
Solved Threads: 0
armen_shlang armen_shlang is offline Offline
Newbie Poster

pointersss...

 
0
  #1
Mar 26th, 2008
hello, Im kinda stuck on how to initialize the class inside the main. Or what to write instead of the ??? inside the main.
Thank you in advance...

  1. //**********************************************************
  2. // Work In Progress
  3. // Author Armen Babakanian
  4. // A complete set of examples to use reference and pointer issues
  5. // in related to functions and classes
  6. //**********************************************************
  7. #include <iostream>
  8. #include <string>
  9. using namespace std;
  10.  
  11. class Job
  12. {
  13. public:
  14. Job(string compName, string titl, double sal)
  15. : companyName(compName), title(titl), salary(sal){};
  16. Job(){};
  17. string& getCompanyName() {return companyName;};
  18. string& getTitle() {return title;};
  19. double getSalary() {return salary;};
  20.  
  21. void setCompanyName(string name) {companyName = name;};
  22. void setTitleName(string name) {title = name;};
  23. void setSalery(double name) {salary = name;};
  24.  
  25.  
  26. private:
  27. string companyName;
  28. string title;
  29. double salary;
  30. };
  31. //*********************************************************8
  32. class person
  33. {
  34. public:
  35. person(string name, string last, string compName, string title, double sal, Job& job)
  36. : m_name(name), m_last(last), m_firstJob(job){};
  37. int getAge(){return m_age;};
  38. string getName(){return m_name;};
  39. string getLast(){return m_last;};
  40.  
  41. void setAge(int age) {m_age = age;};
  42. Job& get1stJob(){ return m_firstJob;};
  43. //------------------------------------
  44. Job* get2ndJob(){ return m_secondJob;};
  45.  
  46.  
  47. private:
  48. string m_name;
  49. string m_last;
  50. int m_age;
  51. Job& m_firstJob;
  52. Job* m_secondJob;
  53.  
  54. };
  55. //*********************************************************8
  56.  
  57. void main()
  58. {
  59. //Job first;
  60. person RafaelB("Rafael","BakerMan", "Starbucks", "maneger", 8.50,Job first);
  61. RafaelB.setAge(22);
  62. cout << RafaelB.getName() << " --" << RafaelB.getLast() << " --" << RafaelB.getAge() << endl;
  63. cout << RafaelB.get1stJob().getCompanyName() << " --" << RafaelB.get1stJob().getTitle() << " --" << RafaelB.get1stJob().getSalary() << endl;
  64.  
  65. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: pointersss...

 
0
  #2
Mar 26th, 2008
You'll have to explain a little better because I don't see the problems you report.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: pointersss...

 
0
  #3
Mar 26th, 2008
//Job first;
person RafaelB("Rafael","BakerMan", "Starbucks", "maneger", 8.50,Job first);
The passing 'Job first' by reference doesn't work. Create 'first' before you call the function, then pass 'first' to the other class's constructor:
  1. Job first;
  2. person RafaelB("Rafael","BakerMan", "Starbucks", "maneger", 8.50,first);

You might want to run a spell checker on your code also
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC