I'm a student who's working on an tourism guide program using xcode. I'm trying to set the object Ds
of type Sport
which is a dynamic array (I think so) to be of type Attraction
. Then I want to pass the new Attraction
object to the setAttraction()
function, but I get the error:
"cannot initialize a parameter of type 'Attraction**' to a lvalue of type 'Attraction*'.
Now I am new to OOP and C++ so I don't what that means.
main.cpp
:
int main() {
int x;
City Rome(111,"Rome");
City Dubai(222,"Dubai");
City Paris(333, "Paris");
cin >> x;
Sport* Ds = new Sport[x];
Culture* Dc = new Culture[x];
Shopping* Dh = new Shopping[x];
//{ new Sport, new Sport, new Sport, new Culture,
// new Culture, new Culture, new Shopping, new Shopping, new Shopping};
Ds[0].setName("Camel and Horse Racing");
Ds[1].setName("Marine Sports");
Ds[2].setName("Football");
Dc[0].setName("Dubai Museum");
Dc[1].setName("Falconry");
Dc[2].setName("Sheikh Saeed Al-Maktoum's House");
Dh[0].setName("Dubai Mall");
Dh[1].setName("Mall of Emirates");
Dh[2].setName("Deira City Centre");
Ds[0].setIDType(1);
Ds[1].setIDType(1);
Ds[2].setIDType(1);
Dc[0].setIDType(2);
Dc[1].setIDType(2);
Dc[2].setIDType(2);
Dh[0].setIDType(3);
Dh[1].setIDType(3);
Dh[2].setIDType(3);
//Here's the problem
Attraction* z = new Attraction[x];
*z = *Ds;
Dubai.setAttraction(z, x);
menu(Rome,Dubai,Paris);
return 0;
}
'City.cpp':
#include "City.h"
#include "Sport.h"
#include "Culture.h"
#include "Shopping.h"
#include <iostream>
#include "Attraction.h"
using namespace::std;
string City::getName(){
return name;
}
int City::getID(){
return id;
}
void City::setAttraction(Attraction a[], int size){
attractions = new Attraction[size];
for (int i = 0; i < size ; i++) {
attractions[i].setName(a[i].getName());//Here's the thread
cout << attractions[i].getName() << endl;
}
for (int j = 0; j < size ; j++) {
attractions[j].setIDType(a[j].getIDType());
}
}
void City::displayAttraction(){
cout << "There you go.\n\n";
for (int i = 0; i < 9 ; i++) {
cout << attractions[i].getName();
}
}