Can't Access Vector's Values After Inserting Values

Hi guys ,

Given the following code :


1
2
3
4
5
6
7
8
9
10
class Pizza {
protected:
	virtual void someFunction(ostream& someOutput) const = 0 ;
public:
	Pizza();
	virtual ~Pizza();
	virtual double funcA() const = 0;
	virtual string funcB() const = 0;	

};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class RegularPizza :public Pizza {

private:
	double m_cost;

protected:
	void someFunction(ostream& someOutput) const;

public:
	RegularPizza();
	~RegularPizza() {};
	double funcA() const;
	string funcB() const;


};



1
2
3
4
5
6
7
8
9
10
class Order {

private:
	std::vector<Pizza*> ordersVector;


public:
void addNewPizza();
// nothing important
}


CPP FILE

1
2
3
4
5
6
void Order::addNewPizza()
{
	Pizza *newPizza = new RegularPizza();
	this->ordersVector(ordersVector.end(),newPizza);

}


from some reason , when I check the length of the vector I get that it's 1.
When I try to send the first cell of the vector as an argument to a method :

main.cpp :
1
2
3
Order * pizzaOrders;
pizzaOrders->addNewPizza();
orderNewPizza(pizzaOrders->ordersVector[0]);         // problematic line , here the code just freeze 


I'd appreciate any help ,
Thank you
Last edited on
closed account (yUq2Nwbp)
you have problem here pizzaOrders->ordersVector[0].........your std::vector<Pizza*> ordersVector is private member so you haven't permission refer to your private mamber from main...
i dont know why you insert pointer from

1
2
3
4
5
6
void Order::addNewPizza()
{
	Pizza *newPizza = new RegularPizza();
	this->ordersVector(ordersVector.end(),newPizza);

}

if i were u,i will
1
2
3
4
5
6
void Order::addNewPizza()
{
	Pizza *newPizza = new RegularPizza();
	this->ordersVector.push_back(newPizza);

}
Topic archived. No new replies allowed.