| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12
Comments:
<0> cause your returning a value <0> ah ic <0> you have to do somehting different for the ***ignment <1> ? <1> god these compiler errors is annoying <1> are <2> how can i transform a string to a int? <2> for example.. transform "12" to 12 .. <0> corstan, your logic is messed up <1> atoi("12") <2> okay, thanks <1> Twister2, I guess the lecturer's is <1> but that can't help me now <0> if you are trying to return a reference, then you have to return something referencable <1> Twister2, take a look at these codes <0> retrun 2.5; does not fly
<1> and try to compile them and link'em <1> wait.. <2> test.cc:27: error: cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `const char*' for argument `1' to `int atoi(const char*)' <3> std::stringstream cvt("12"); int x; cvt >> x; // x is now 12 <3> Use that. <3> #include <sstream> <3> More generally... <3> std::stringstream cvt; cvt << "12"; int x; cvt >> x; <3> Or, what you seem to be doing... <2> :D.. isnt there a function to do that? :D <3> std::string foo = "12"; std::stringstream cvt; cvt << foo; int x; cvt >> x; <1> Twister2, <3> That function isn't as extensible or as flexible as std::stringstream <1> MyVector.cpp: http://www.noidea128.org/sourcefiles/15818.html <3> Obviously, you're having trouble with it. <3> atoi can only convert a const char* to an integer. <3> std::stringstream can convert anything to anything else. <3> That's a big win. <1> Twister2, MyVector.h: http://www.noidea128.org/sourcefiles/15819.html <3> If there's an overloaded operator>> and operator<< for a type, std::stringstream can use it. <3> atoi knows not of such things. <1> then main.cpp: http://www.noidea128.org/sourcefiles/15820.html <1> try building <1> and tell me <1> anything Twister2 + <0> u have 2 identical prototypes <0> MyVector &MyVector::operator()(int i) { /*modify index i */ return this; } <0> that would be my initial thought <0> err, well thats not correct either <0> it might be something like this: <3> I hope someone has pointed out that it should be operator[] <3> operator() has another purpose. <1> Solamente, we had that discussion :) <0> yeah, thats basically what is confusing the hell out of me <3> And your reason for using () is? <1> Solamente, a Matlab feature :) (no flaming) <3> That's pretty dumb. This isn't Matlab. <1> Twister2, what were you saying? <0> it would be: double &MyVector::operator()(int i) { return A[i]; } or something like that. <0> but as Solamente stated, normally it is the [] operator <1> for doing something like: a = v(i) ? <3> a = v[i]; <0> its a = v[i] <3> [] is the index operator <1> yes, I know <0> () is function object operator <1> but I have to confine myself to the task specification <1> bear with me <3> I'd only recommend () for a Matrix type, where a = matrix(x,y); makes more sense <3> It's a nutty specification <0> well, anyways, did you try the above? <1> Solamente, this syntax is extended to what you are refering to, matrices later <1> Twister2, I have already this: <0> before the return, you should check bounds though <1> / a = v(i) <1> 51: double MyVector::operator() (int i) <1> 52: const <1> 53: { <1> 54: return A[i]; <1> 55: } <1> that is for extracting values from a vector
<1> but I need to figure out how to a body for: <1> double &operator() (int i); // v(i) = a; <0> I just told you it <1> iaw, ***igning new values to the vector <1> ok <0> you need a const version too though I think <1> talking about what I pasted ? <0> and you have to bounds check... <1> there's a const there <0> Your totally missing the entire point of a vector cl*** by ignoring bounds <0> unless you want () to be unsafe index <1> this is merely an exercise in learning cl***es and header files <1> I'll ignore out of bounds stuff <0> I meant you need double const &MyVector::operator() (int i) const { } too <4> Twister2: Why? <0> I dunno <0> :) <4> Returning a reference lets you do lhs stuff. I'm not sure what returning a const reference would give you <1> ok, anyways I see that whenever I am dealing with &operator() in a cl*** <5> it would only give you the ability to take it's address <1> I just do: double &MyVector::operator() ... <0> well, the const one should be public <0> I think <4> corstan: & doesn't deal with the operator. & deals with the double. <3> Twister2: [] doesn't do bounds checking, for efficiency. <3> What corstan is doing, however, should probably do bounds checking. <1> what is exactly happening here: <0> actually.. I just totalyl confused myself <1> double &MyVector::operator()(int i) <1> { <1> return A[i]; <1> } <1> I am returning the address of an entry in A? <3> No. <3> You're returning a reference. <1> sorry, what I meant, the '&' <3> But it's not going to work. <1> Solamente, it is... :) <1> it does <3> What is A? <1> a data member of cl*** MyVector <3> I don't want to ask what MyVector is. <1> another basic question: <1> what's the point of putting 'const' here: <1> double MyVector::operator() (int i) const {....} <1> ? <1> and also in the prototype in the h-file <0> its just saying the member will not modify the object <1> you mean the operator overloading function? <0> meaning that v(i) <=== v will not be modified. <3> Which is clearly incorrect if you're returning a non-const reference. <0> no, thats for the other prototype <3> Okay. <0> and yeah, returning a const reference might be needed for some situation I suppsoe <3> No, a copy is fine. <0> ok <5> sometimes you want to be able to do, double* d = &matrix(0, 1); though a different approach to that should be considered first <3> You have. You just didn't realize it. <1> Solamente, talking to me? <3> Of course. <1> heh <3> Any time you're p***ing a parameter by reference to a function, and the function should not modify it, the parameter should be const. <3> If you're not, you're tempting the devil. <1> ok <1> but what about const functions <3> Likewise if the parameter is not a trivial type, but has value semantics. <1> any similar examples there? <3> It should be a const reference. <3> Any time the method does not change the state of the object, it should be const. <6> i am trying to change the caption of a button in vc++ what is teh correct command buttonname->?? <3> That way it can be used on const instances of the type. <3> vERYbIGnOSE: SetWindowText, and that's not really a C++ question. <6> ok thanks
Return to
#c++ or Go to some related
logs:
Undernet Kilroy #linuxhelp scoutmd nocti css E: Couldn't find package vsftpd #php Directory index forbidden by rule - fedora 4 #teens #php #AllNiteCafe
|
|