c++ - printing values vector f[0] -


assuming have fraction class , want keep them in vector did create fraction vector

however, don't know how read value inside vector, reading mean printing value out

it turns out f[0] print out address of fraction instead of data of fraction

void main() {     fraction fr(2,5);     vector<fraction*> f;     f.push_back(&fr);     cout<<f[0]<<endl; } 

you're storing pointers fraction in vector: vector<fraction*>.

cout << f[0]->numerator << "/" << f[0]->denominator << endl; 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -