Wednesday, 18 September 2013

Using pointers references

Using pointers references

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);
}
I believe the problem is in the first line in method SetProduct... But,
what can I change to it works? Thanks

No comments:

Post a Comment