main.cpp:98:10: error: request for member ‘setname’ in ‘* it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Stock**, _Container = std::vector<Stock*>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = Stock**]()’, which is of non-class type ‘Stock*’
main.cpp:99:10: error: request for member ‘setprice’ in ‘* it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Stock**, _Container = std::vector<Stock*>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = Stock**]()’, which is of non-class type ‘Stock*’
main.cpp:100:10: error: request for member ‘display’ in ‘* it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Stock**, _Container = std::vector<Stock*>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = Stock**]()’, which is of non-class type ‘Stock*’
i dont get it ... why didnt those member functions werent created?
You are dereferencing incorrectly, which leaves you with a pointer to a pointer Stock**.
Change:
*it->setname() to (*it)->setname().
In other words *it-> dereferences the iterator, not the object that the iterator points to.
By changing it to (*it)-> you are performing similar pointer arithmetic to **it->, only this is the correct way.
That is correct. He would want to either cast the element of the vector or create a list
of derived objects before using setname(). Ideally, you want to include setname(), etc to the base class to begin with :)
@johnnystarr
Its just an excercise for getting to know more about virtual functions ... i have to make a program that creates these stocks derived from Stock, which i could later manipulate its name or price or display them on screen. Using of course the the Stock as and abstract class
@Melan
dont worry melan i noticed that... this is just a quick thought...
@kfmfe04
dont worry man... this is just the first step to getting to know virtual functions...
It might help to lose the vector. I've found that when I'm trying to brush up on a core aspect of
a language, it helps to write very small applications that strictly focus on that subject. Once you
get a feel for that, then maybe you could at a container of objects.