Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Vector of pointer of P...
//clang 3.8.0 #include <iostream> #include <vector> using namespace std; class P { public: P(int p):i(p) { } int getElem() {return i;} private: int i; }; int main() { cout << "Hello, world!\n"; vector<int> vi; vi.push_back(10); vi.push_back(20); vi.push_back(30); for(auto elem: vi) cout << elem << endl; cout << endl; vector<P> vp; vp.push_back(P(100)); vp.push_back(P(200)); vp.push_back(P(300)); for(auto p: vp) cout << p.getElem() << endl; cout << endl; vector<P*> vpp; vpp.push_back(new P(1000)); vpp.push_back(new P(2000)); vpp.push_back(new P(3000)); for(auto pp: vpp) cout << pp->getElem() << endl; cout << endl; vector<P*>::iterator vectorBeginIter = vpp.begin(); vector<P*>::iterator vectorEndIter = vpp.end(); while(vectorBeginIter != vectorEndIter) { cout << (*vectorBeginIter)->getElem() << endl; vectorBeginIter++; } cout << endl; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
GreedyProblem1
ternary test
Tilted uniform distribution random number generator over min/max range
__FUNCTION__ not a preprocessor macro on clang
sort
Sum of Natural Numbers using loop
1337
user defined exception
general
Crow unordered_map Quiz
stackse - search stackoverflow differently
Please log in to post a comment.