Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. // File 1 "Koulutusohjelma"
  2.  
  3. #include <string>
  4. #include <vector>
  5. #include "Opettaja.h"
  6. #include "Opiskelija.h"
  7. using std::string; using std::vector;
  8. class Koulutusohjelma
  9. {
  10. public:
  11. Koulutusohjelma();
  12. Koulutusohjelma(string nimi);
  13. ~Koulutusohjelma();
  14. vector <Opettaja> opettajat_; <------------ This is the vector which I need in file 2
  15. private:
  16. string nimi_;
  17. vector <Opiskelija> opiskelijat_;
  18. };
  19.  
  20.  
  21. ////////////////// File 1 cpp
  22.  
  23. #include "Koulutusohjelma.h"
  24.  
  25. void Koulutusohjelma::lisaaOpettaja() /////////////// This is where I add contents to the vector
  26. {
  27. Opettaja tmp; // apuolio
  28. tmp.kysyTiedot();
  29. opettajat_.push_back(tmp); // Lisätään opettaja vectoriin
  30. }
  31.  
  32. void Koulutusohjelma::tulostaOpettajat() const //////////// This succesfully prints the contents of the vector
  33. {
  34. for (unsigned int i = 0; i < opettajat_.size(); i++)
  35. opettajat_[i].tulosta();
  36. }
  37.  
  38. ############# File2.h "Koulu"
  39. #include <string>
  40. #include <vector>
  41. #include "Koulutusohjelma.h"
  42. class Koulu :
  43. public Koulutusohjelma //////// Now properly inherits from file 1
  44. {
  45. public:
  46. Koulu();
  47. Koulu(string nimi);
  48. ~Koulu();
  49. void poistaKoulutusOhjelmanOpettaja(); ///////// Here I need the vector
  50. private:
  51. int etsiKoulutusohjelma() const;
  52. string nimi_;
  53. vector <Koulutusohjelma> koulutusohjelmat_;
  54. };
  55.  
  56. /////////// File2.cpp
  57.  
  58. #include "Koulu.h"
  59. #include <iostream>
  60. using std::cout; using std::endl; using std::getline; using std::cin;
  61.  
  62. void Koulu::poistaKoulutusOhjelmanOpettaja() //////// This is where I need the vector
  63. {
  64. string nimi;
  65. string tunnus;
  66. cout << "Anna koulutusohjelman nimi: ";
  67. getline(cin, nimi);
  68. cout << opettajat_.size() << endl; /////// This is where I test if vector has contents, prints out 0
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement