Search Results

Search found 3 results on 1 pages for 'johnyy'.

Page 1/1 | 1 

  • Question of using static_cast on "this" pointer in a derived object to base class

    - by Johnyy
    Hi, this is an example taken from Effective C++ 3ed, it says that if the static_cast is used this way, the base part of the object is copied, and the call is invoked from that part. I wanted to understand what is happening under the hood, will anyone help? class Window { // base class public: virtual void onResize() { } // base onResize impl }; class SpecialWindow: public Window { // derived class public: virtual void onResize() { // derived onResize impl; static_cast<Window>(*this).onResize(); // cast *this to Window, // then call its onResize; // this doesn't work! // do SpecialWindow- } // specific stuff };

    Read the article

  • Copy constructor called even when returning by reference?

    - by Johnyy
    Hi, I am testing the return of local objects by reference. My original test went well but something else happens unexpected. #include <iostream> using namespace std; class MyInt { public: MyInt(int i){ value = new int(i); } ~MyInt(){ delete value; } int getValue(){ return *value; } MyInt(const MyInt &b){ cout<<"Copy"<<endl; } private: int* value; }; MyInt& returnref(){ MyInt a(10); cout<<"Returning from returnref()"<<endl; return a; } int main(){ MyInt a = returnref(); cout<<a.getValue()<<endl; return 0; } My console prints "Returning from ..." then "Copy" then a random value. My understanding of pass by reference is that it does not need to make any copy. Why is it not doing what I expected?

    Read the article

  • Shell script exiting the loop after calling another script

    - by Johnyy
    Hi Guys, I have a shell script s1 calling another script s2 in a loop. However s1 can not seem to continue the loop after s2 returns. Commenting out the line that calls s2 will enable the loop to continue. s2 does copy of one file, s1 checks conditions and copy several files using s2. Can anyone give a pointer what is going on here? ... while read line s2 param1 param2 param3 echo "copy done" done < $tempfile echo "out of loop" ... "copy done" is printed, so is "out of loop"

    Read the article

1