I need use a var from pointer reference in another function, so, when I call that I pass the address value, but how can I use this pointer there (not creating another instance)? Look the code segment:
//Main region - using Product class -> _products = vector<Product>
int main()
{
_products.reserve(2);
for(i=0;i<2;i++)
productRefe.SetProduct(&_products);
return 0;
}
//Method in Product.cpp
void Product::SetProduct(vector<Product> *productsP)
{
vector<Product> products = *productsP;
Product productInsert;
cout << "Type the description: ";
cin >> productInsert.Struct.description;
products.push_back(productInsert);
}
void Product::GetProducts(string description, bool all, vector<Product> *productsP)
{
int i = 0;
vector<Product> products = *productsP;
if(all)
for(i = 0; i < products.size(); i++)
{
cout << "Description: " << products[i].Struct.description << endl;
cout << "Value" << products[i].Struct.value << endl << endl;
}
}
I believe the problem is in the first line in method SetProduct... But, what can I change to it works? Thanks