Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Vector examples....
//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"; int a =10, b = 20, c = 30; vector<int> vi; vi.push_back(a); vi.push_back(b); vi.push_back(c); for(auto elem: vi) cout << elem << endl; cout << endl; vector<int*> vip; vip.push_back(&a); vip.push_back(&b); vip.push_back(&c); for(auto ip: vip) cout << *ip << endl; cout << endl; vector<P> vp; vp.push_back(P(100)); vp.push_back(P(200)); vp.push_back(P(300)); for(auto elem: vp) cout << elem.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 elem: vpp) cout << elem->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
bubble sort
MPL 2-0
chakib
1337
Dynamically allocated array in unique_ptr with custom deleter.
Virtual Function Example
Fun with Pointers #2
What's the problem with this?
using directives: qualified lookup rules are different from unqualified lookup rules
Tree Example