Help Logs Database

Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Ircnet  |  Dalnet
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

<[proxy]> cl*** foo{vector<int> v;;int& operator[](int j){if(j > vector.size()) v.resize(j); return v[j];} or something like that
<kick***_6> YUY0x7: I just put the function itself, I dont need a header above the function do I?
<palomer> [proxy]: good point
<blaze02> palomer, you wrote your own vector cl***?
<palomer> [proxy]: ahh, but here's the deal: I only want to resize if I'm going to ***ign
<YUY0x7> kick***_6, just put the function signature in the header
<YUY0x7> then define it somewhere in the source files
<palomer> blaze02: nonono, I'm using deque's to implement some other container
<[proxy]> palomer: that's why there are const and non-const versions of operator[]
<[proxy]> only resize on the non-const one (where you could potentially ***ign)
<palomer> the compiler will choose the right one?
<[proxy]> indeed
<[proxy]> and it will have an easier time doing so if you use proper const correctness in your code
<YUY0x7> foo f; f[10]; // will call the non-const one
<blaze02> yep
<[proxy]> (make things const if they dont change....)
<YUY0x7> palomer, write a cl*** that you return on operator[]
<palomer> so I make two methods: const int operator[](int i) and int& operator[](int i) ?
<[proxy]> palomer: close...
<YUY0x7> that will have operator= overloaded as well as operator int
<stevieo> int operator[](int) const; int operator[](int);
<palomer> YUY0x7: oh no, the cl*** is written by someone else
<palomer> isn't it int&?
<[proxy]> stevieo: you forgot ref
<stevieo> Yes probably & for the non const
<YUY0x7> palomer, but you can change it can't you?
<palomer> YUY0x7: it's part of some huge package
<palomer> of which I'm frightfully afraid of
<palomer> sorry
<kick***_6> whats the difference between a cpp file and a cc file? (my files are ccp but my given files are cc)
<[proxy]> nothing
<[proxy]> c++ has several commonly accepted extentions for it's source file, it is strictly a matter of preference
<stevieo> I tried cccp file, but the fbi came to visit
<[proxy]> lol
<kick***_6> thanks.
<kakun> we're you runnig Lenix as well, stevieo?
<YUY0x7> palomer cl*** foo { vector<int> v; struct container { vector<int>& v_; int i_; container(vector<int>& v, int i) : v_(v), i_(i) {} container& operator=(int x) { if (i_ < v.size()) v.resize(i_+1); v[i_] = x; } operator int() { return (i_ < v.size()) ? v[i_] : 0; } }; public: ... container operator[](int i) { return container(v, i); } .... };
<stevieo> Marxist Lenix
<YUY0x7> just if you're interested in how it can be done... or if you actually want to use something like that
<kakun> stevieo, http://lez.ath.cx:800/~ohsix/images/russianlenix.png
<palomer> YUY0x7: how does that work?
<YUY0x7> foo f; f[10]; // doesn't resize
<stevieo> I'd expect int operator=
<kakun> stevieo, and may the party be with thou, comrade.
<Symmetry_> kakun, lol
<YUY0x7> foo f; f[10] = 10; // calls container::operator=, it resizes
<stevieo> cute
<Symmetry_> Starting Government Services, lol
<kakun> huhu, welcome, brother Symmetry.
<kakun> Today, a geek, POSIX compliant OS. Tomorrow - the World!!11
<kakun> geeky, even.
<kakun> spec, the SSE documentation in Intel's instruction set reference is very ****ty. could you recommend a better source?
<Symmetry_> why, good to see you, comrade Kakunov.
<Symmetry_> though 40, Demi Moore feels like a 25 year old inside
<FBKK> anyone worked with WMP 10 SDK ?
<ZorbaTHut> man, death keeps kicking my ***
<ZorbaTHut> I think it's time for bed


Return to c++
or
Go to some related logs:


Copyright © 2005 www.irclogs.ws. All rights reserved. » disclaimer » contact