I have this code:
#ifndef APPSYSTEM_H
#define APPSYSTEM_H
#include "Application.h"
#include <iostream>
#include <exception>
#include <vector>
using namespace std;
class AppSystem{
private:
vector<Application &> &ApplicationVector;
public:
AppSystem(vector<Application &> &); //AppSystem Constructor
AppSystem(const AppSystem &); //Copy constructor
void setApplicationVector(vector<Application &> &); //set the AppSystem's Application Vector
vector<Application &> getApplicationVector(); //get the AppSystem's Application Vector
virtual ~AppSystem(); //Destructor
};
#include "AppSystem.h"
#include <iostream>
//AppSystem Constructor
AppSystem::AppSystem(vector<Application &> &appSystemVector){
ApplicationVector = appSystemVector;
}
//Copy constructor
AppSystem::AppSystem(const AppSystem &appSystem){
ApplicationVector = appSystem.ApplicationVector;
}
//set the AppSystem's Application Vector
void AppSystem::setApplicationVector(vector<Application &> &applicationVector){
this->ApplicationVector = applicationVector;
}
//get the AppSystem's Application Vector
vector<Application &> AppSystem::getApplicationVector(){
return this->ApplicationVector;
}
//Destructor
AppSystem::~AppSystem(){
cout << "Destroying AppSystem Object " << endl;
}
#include "AppSystem.h"
#include "Application.h"
#include "ApplicationConstructor.h"
#include "UserOpinion.h"
#include "MyExceptions.h"
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main(int argc, char** argv) {
ApplicationConstructor appConstructor1("3324","Konstantinos Dimos", "[email protected]");
ApplicationConstructor appConstructor2("3332","Nikos Paulou", "[email protected]");
ApplicationConstructor appConstructor3("4432","Stavros", "[email protected]");
Application app1("game1456", "Tetris", "1.0.0", appConstructor1, NULL, 10.0);
Application app2("game2245", "Pacman", "1.1.0", appConstructor2, NULL, 15.0);
Application app3("game1433", "Doom", "1.1.1", appConstructor3, NULL, 20.0);
/*-----------------------------------------------------------------------------------------------------*/
ApplicationConstructor appConstructor4("2232","Eirini Markou", "[email protected]");
ApplicationConstructor appConstructor5("1121","Tasos Sotiriou", "[email protected]");
ApplicationConstructor appConstructor6("4431","Giorgos Papadopoulos", "[email protected]");
Application app4("desk4552", "Office", "1.0.0", appConstructor4, NULL, 30.0);
Application app5("desk6657", "Photoshop", "1.1.0", appConstructor5, NULL, 25.0);
Application app6("desk6643", "Torrent", "1.1.1", appConstructor6, NULL, 45.0);
/*-----------------------------------------------------------------------------------------------------*/
Application appTable[] = {app1, app2, app3, app4, app5, app6};
vector<Application &> appVector(appTable);
AppSystem appSystem(appVector);
}
And I get this error:
AppSystem.cpp:12:1: error: uninitialized reference member in 'class std::vector&' [-fpermissive]
AppSystem::AppSystem(vector &appSystemVector){
^~~~~~~~~
In file included from AppSystem.cpp:8:0:
AppSystem.h:21:32: note: 'std::vector& AppSystem::ApplicationVector' should be initialized
vector &ApplicationVector;
Any suggestion?
ApplicationVectora reference?vector<Application &> &ApplicationVector;-- Why are all of these references? Why not a plainvector<Application> ApplicationVector;?std::reference_wrapper.reference_wrappers. But why do you want to use references at all?