Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File 1 "Koulutusohjelma"
- #include <string>
- #include <vector>
- #include "Opettaja.h"
- #include "Opiskelija.h"
- using std::string; using std::vector;
- class Koulutusohjelma
- {
- public:
- Koulutusohjelma();
- Koulutusohjelma(string nimi);
- ~Koulutusohjelma();
- vector <Opettaja> opettajat_; <------------ This is the vector which I need in file 2
- private:
- string nimi_;
- vector <Opiskelija> opiskelijat_;
- };
- ////////////////// File 1 cpp
- #include "Koulutusohjelma.h"
- void Koulutusohjelma::lisaaOpettaja() /////////////// This is where I add contents to the vector
- {
- Opettaja tmp; // apuolio
- tmp.kysyTiedot();
- opettajat_.push_back(tmp); // Lisätään opettaja vectoriin
- }
- void Koulutusohjelma::tulostaOpettajat() const //////////// This succesfully prints the contents of the vector
- {
- for (unsigned int i = 0; i < opettajat_.size(); i++)
- opettajat_[i].tulosta();
- }
- ############# File2.h "Koulu"
- #include <string>
- #include <vector>
- #include "Koulutusohjelma.h"
- class Koulu :
- public Koulutusohjelma //////// Now properly inherits from file 1
- {
- public:
- Koulu();
- Koulu(string nimi);
- ~Koulu();
- void poistaKoulutusOhjelmanOpettaja(); ///////// Here I need the vector
- private:
- int etsiKoulutusohjelma() const;
- string nimi_;
- vector <Koulutusohjelma> koulutusohjelmat_;
- };
- /////////// File2.cpp
- #include "Koulu.h"
- #include <iostream>
- using std::cout; using std::endl; using std::getline; using std::cin;
- void Koulu::poistaKoulutusOhjelmanOpettaja() //////// This is where I need the vector
- {
- string nimi;
- string tunnus;
- cout << "Anna koulutusohjelman nimi: ";
- getline(cin, nimi);
- cout << opettajat_.size() << endl; /////// This is where I test if vector has contents, prints out 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement