I have a base class that includes a virtual method and a cast operator:  class Base { public:     Base() {}     operator int() const { return getInt(); } protected:     virtual int getInt() const { return 0; } }   Then I have two derived classes that override the virtual method:  class Derived1 { public:     Derived1() : Base() {} protected:     virtual int getInt() const override { return 1; } }  class Derived2 { public:     Derived2() : Base() {} protected:     virtual int getInt() const override { return 2; } }   Then I have a helper function:  Base helper(const bool flag) {     if (flag)         return Derived1();     else         return Derived2(); }   The intention of that helper function is to be used like:  int one = helper(true); // I expect "one" to be 1 int two = helper(false); // I expect "two" to be 2   But both one and two contain 0. I have no idea how to resolve this. Is the cast operator getting called before the Derived classes are fully constructed? My environment is VS2013.    Suggested fix (in my case, after answers)  I ended up turning the helper function into a class which stores Deriveds as members and returning a reference to them (which I believe is actually a better design since on each [] call a Derived does not get constructed / allocated):  class Helper { public:     Helper();     const Base&amp; get(const bool flag) const {         if (flag)             return mDerived1;         else             return mDerived2;     } private:     Derived1    mDerived1;     Derived2    mDerived2; }     Side note  Accepted answer suggests that the gist of the question is thinking about everything as in references (like Python) and that is true. This issue came up as a part of a bigger system design which allows access to results returning from a SQLite database with a Python like syntax in C++. Chaining square brackets like: mData[0][1].
Someone mentioned it in the IRC as the slicing problem.
How to cite a book chapter written by an author who is not the editor or author of the book with BibTeX? I don't know how to cite a chapter written by an author who is not the editor or author of the book.   How can I get the following citation?     Grandstrand, O. (2004), 'Innovation and Intellectual Property Rights', in J. Fagerberg, D.C. Mowery and R.R. Nelson (Eds.), Oxford Handbook of Innovation. Oxford University Press: Oxford. I need to make a small correction in a video I uploaded to YouTube. Googling shows that this is not possible. However, I remember seeing it done before. I posted a comment on a video saying that a certain part of the video was missing. I got a reply back that it was fixed, and when I went to see the video again, it was changed. How was this done? Use of # a.k.a. read-macro Prove that for $ 0&lt;x&lt; \pi $, $$ \quad S_n(x) = \sin x + \frac{ \sin3x }{3} + ... + \frac{ \sin((2n-1)x) }{2n-1} &gt;0 \quad \forall n = 1,2,... $$  Having trouble with this problem. This is an olympiad-style question, so an answer that doesn't use calculus or analysis would be preferred. A possible approach is induction, but for this we need to find a function in terms of $n$ and $x$ so that we can actually use the inductive step. If anyone has any ideas they would be appreciated.  If you really want to go down the calculus route (at this point I don't mind), then $ S_n' (x) = \cos x + \cos 3x + ... +\cos((2n-1)x) $ , which you can find a closed form for, but I don't know how useful that is. I was looking at  and I didn't realize that Minecraft had some Easter eggs in it. Besides the Christmas chest Easter egg, and the sheep Easter egg, what else is there? How can I recursively delete all files of a specific extension in the current directory? How do I safely delete all files with a specific extension (e.g. .bak) from current directory and all subfolders using one command-line? Simply, I'm afraid to use rm since I used it wrong once and now I need advice. Are there any hash outputs not produced by the MD5 hash function? I need to use it as a placeholder for an empty hash while comparing two hashes. What do you call a person who is utterly independent and a loner? Assign z values to depth curves in QGIS I'm new to QGIS and working with GIS in general (student of architecture), so please bear with me.  I have obtained shapefiles with topographic curves of an ocean floor. My intention is to export these as CAD files and render as 3D models of the ocean floor in Revit. I have done this procedure earlier with terrain shapefiles. My problem now is that these files mapping depth does not contain z values, so when exporting them into CAD they are completely flat rather than 3D models.  The depth information in meter exists as attributes in the file (see attached image). What I want is to transform this depth value into real z coordinates for each line so that the curves have different heights when importing as CAD file in Revit.  Thankful for any pointers in the right direction. Backstory: I've been developing a game with LibGDX for the past two years, and I've seen it refactored more times than I remember.  I jumped on the iOS iKVM port as soon as it was released. But I've been struggling with it ever since in regards to cross platform networking.  Kryonet will not port over to iOS unfortunately. So it's either I ditch Kryonet, or lose a large chunk of my target audience (iOS Users)  My question for you is:  I noticed LibGDX has cross platform classes ready for sockets and HTTP Requests, but no documentation exists for these sockets at all.  Has anyone used these sockets at all in the past, and does anyone know how they work? How is money held in escrow for a home purchase from a IRA treated by the IRS? How to tile textures in Cycles? Best way to do multi-row insert in Oracle? How to clone all remote branches in Git? I have a master and a development branch, both pushed to . I've cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back.  I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all. I know you can export the asset as a PSD and open it in Photoshop. Is there a more seamless way?  Update:  I'm an idiot.  Someone else created the logo, and the shadow was it's own layer on multiply and not a normal drop shadow effect. How to flash a BIOS when only a Windows binary is provided? I came to Netherlands from Dubai on a business visa. Now I wish to travel to Paris by train and after two days wish to leave to Dubai direct from Paris. Am I allowed to exit Paris to Dubai when the entry stamp in my passport is Amsterdam? I would like to upgrade my main system to 16.04, but I work on projects that require OpenJDK 7.   Apparently it is not available from a trivial apt-get install openjdk-7-jdk. Only versions 8 and 9 are listed in the repository.  Can anyone point me to instructions on how to install it? Does there exist an automorphism of $\mathbb{C}$ that does not keep $\mathbb{R}$ fixed? Lipschitz Condition and Optimization I am reading paper on . I am trying to understand the following statement:     I would like to ask how the Ball doesnot contain the minimum of f? I would appreciate if this could be graphically shown something like following taken from Bayesian Optimization and Data Science