I have two base classes Vehicle and WorkerUnit and they have derived classes Bus and Maintenance respectively.  The Maintenance class has to be initialized with a variable of class Vehicle (or the derived classes of Vehicle), and the function print() inside class Bus is to be called. How do I achieve this?  #include &lt;iostream&gt; using namespace std;  // Vehicle Class class Vehicle { public:     virtual void print() {         cout &lt;&lt; "Vehicle print() called" &lt;&lt; endl;     } };  class Bus : public Vehicle { public:     void print() {         Vehicle::print();         cout &lt;&lt; "   Bus print() called" &lt;&lt; endl;     } };  // Worker Unit Class class WorkerUnit { protected:     Vehicle vehicle; public:     WorkerUnit(Vehicle vehicle) : vehicle(vehicle) {}     virtual void print() {} };  class Maintenance : public WorkerUnit { public:     Maintenance(Vehicle vehicle) : WorkerUnit(vehicle) {}     void print() {         // Problem here where function calls base class Vehicle's print()         // How do I actually call the derived class's print()?         vehicle.print();     } };  int main(void) {     Bus *bus = new Bus();     Maintenance *m = new Maintenance(*bus);     m-&gt;print();      return 0; }
Someone mentioned it in the IRC as the slicing problem.
A riddle about guessing hat colours (which is not among the commonly known ones) This is a riddle I heard recently, and my question is if someone happens to know the solution. I'm asking this out of curiosity more than anything else.  So here it is. The riddle is one of the countless variations of the "prisoners have to guess their hat colour" puzzle. $n$ prisoners are put a hat on top of their head, which can be red or blue. The colours are chosen at random by $n$ independent fair coin tosses. Then each prisoner can guess their own hat colour (red or blue) or pass. The prisoners can see each other, but not hear each other's calls and of course they have no other means of communication. This means that each call can only depend on the other prisoners' hat colours. However, before the distributing of hats begins, the prisoners are told the rules and can agree on a strategy. The prisoners win iff no prisoner guesses wrong and at least one prisoner guesses right. Which strategy should the prisoners use so that the winning probability becomes maximal?  Some remarks:   A simple strategy is that one player just guesses and all other players pass, so that the maximal probabilty is at least 1/2. For $n=2$ this strategy is optimal. For $n=3$, there is a strategy that wins in 6 out of 8 cases: When a player sees (red,red) he guesses blue, for (blue,blue) he guesses red, and otherwise he passes. More generally this shows that the maximal probability is at least 3/4 for $n\ge 3$. It's possible to show that any strategy fails for at least 2 hat colour configurations (unless $n=1$), which shows that the above strategy is optimal for $n=3$. For $n=4$ there are more than $10^{15}$ strategies, and for $n=5$ it's about $10^{38}$ strategies, making it quite infeasible to just use a brute-force computer program (maybe for $n=4$ it's possible when exploiting the obvious symmetries). When changing the rules slightly by forbidding players to pass, then the maximal winning probability is always 1/2. This is a nice little exercise.   Actually I heard the riddle only for $n=3$ and then thought about the general $n$. So it's entirely possible that there is no nice solution. Thor: Ragnarok ends with the remaining people of Asgard aboard a refugee ship that meets Thanos' ship. Avengers: Infinity War opens with      Thanos and his minions having commandeered the ship and several bodies can be seen on the floor.   This begs the question, what happened to these characters:   Korg Miek Asguardian extra #3 Valkyrie pyvenv vs venv vs python-virtualenv vs virtualenv and python 3 malikarumi@Tetouan2:~$ pip install virtualenv     Collecting virtualenv     Downloading virtualenv-12.0.7-py2.py3-none-any.whl (1.8MB)     100% |################################| 1.8MB 330kB/s   malikarumi@Tetouan2:~$ pip freeze     (a lot of stuff, but not virtualenv)  malikarumi@Tetouan2:~$ virtualenv testvenv1     The program 'virtualenv' is currently not installed. You can install it by typing:     sudo apt-get install python-virtualenv   What is going on here? is python-virtualenv == pyvenv? Isn't that still broken? Does original virtualenv still work with python? if venv (too many name variations!!!) is part of the standard library, , why am I being told to install it?  And when I did try to install it, I got:  malikarumi@Tetouan2:~$ sudo apt-get install python-virtualenv     Reading package lists... Done     Building dependency tree            Reading state information... Done     The following extra packages will be installed:     python-colorama python-distlib python-html5lib python-pip python-setuptools   At which point I aborted, because installing python3-pip just before that had given me   Setting up python3-setuptools (3.3-1ubuntu1) ... Setting up python3-pip (1.5.4-1) ...   And I wasn't sure if the extra packages would overwrite them or go onto python 2.7.  I read that python 3 is supposed to be the default going forward. Since both 2.7 and 3.4 are there, and have separate commands, how do I not only make sure Python 3 is my default, but that anything I install goes there and is used by it instead of 2.7?   BTW, I tried sudo apt-get python3-virtualenv and got: E: Unable to locate package python3-virtualenv Can I get back my saved data? Windows OS on external hard drive Is it possible to install Windows OS to plug and play storage devices such as external hard drives, HDD enclosures (with SATA hard drives), USB flashdrives and the likes? What OS's? And if it's possible, can I boot on it after the installation/formatting?  I've read someone has tried this already using Windows XP but failed since XP reinitializes all attached USB devices before loading OS, thus disabling the External HDD that is attached via USB port.  What about other Windows OS: on Windows 7 or 8.... or Windows 10?  I'm asking this because I'm planning to create a portable OS. When I'm at my house, when I go to my grandmother's, or to a friend's place: I just simple plug that portable storage device, change the boot priority, and turn on the system and ta-da! I will only see one environment every time. Disable ohead on a single page Is there a way to disable certain Windows 7 keyboard shortcuts?  Specifically, in this case, I want to disable Alt+Space and WinKey+Space. Teenagers find an ancient lizard creature in stasis and accompany him on adventures to an undersea city When I was a kid, I read a book (likely from the '60s) about a pair of kids who find an ancient lizard/fish man inside a cave. The cave has been recently exposed by an earthquake and the creature is inside a super technologically advanced stasis chamber. I think this creature's name is something like "Sslaa". He takes the kids on a quest to find his lost underwater city.  They end up finding the city, which is still populated by creatures like himself and protected from the ocean above by an immense diamond dome. Eventually, Sslaa has to drive an advanced mining vehicle deep into the crust of the earth, presumably to prevent his city's destruction by an impeding magma flow or other seismic event.  For extra obscurity bonus points, I could swear I managed to find this book on Google several years ago, and was shocked to learn that it had originally been written in German, and then translated to English.  Does anyone out there recognize this one? I'm using a  freely downloadable latex class file and the style is set to \bibliographystyle{ieeetr}. But when I cite something with \cite{} I get it inside ().   For example I get it as abc et al. (1) but what I want to get is abc et al. [1].   Please tell me how to get my citations inside [ ] ? In addition to showing reputation scores, SO should rank users. In the users section, users are ordered by the reputations they have.  Each user should also have a unique rank, since many users can have the same reputation score.  Rank must follow the order laid out by reputation, but for those having similar reputation, an additional formula should be defined which can rank users based on tags, time since registration, frequency of activity and/or helpfulness of their answers.  What are your thoughts on this? How do you unlock the Dream Suite? The server version of Ubuntu does not have the  command. How can I add a  (PPA) to the server without this command? How to embed Stack Overflow flair in a WordPress.com (free) blog? Has anyone successfully embedded their  on a WordPress.com-hosted blog?  The free hosted version of  (not )  from all posts before publishing. So they to strip out just about anything I can add to embed my Stack Overflow flair.  Note: I'll be switching to a paid, hosted site in the future (fixing the problem), but I'm looking for a quick, short-term solution. How to prove that $\mathbb{Q}$ ( the rationals) is a countable set I want to prove that $\mathbb{Q}$ is countable. So basically, I could find a bijection from $\mathbb{Q}$ to $\mathbb{N}$. But I have also recently proved that $\mathbb{Z}$ is countable, so is it equivalent to find a bijection from $\mathbb{Q}$ to $\mathbb{Z}$? Decode Base64 data in Java My awk program to change spaces into tabs doesn't work How to write a shell script which uses awk to read in the data file students.txt and output the data in the tabbed format as shown:  Surname Forename MSc Stream Date of Birth Smith John IT 15.01.1986 Taylor Susan IT 04.05.1987 Thomas Steve MIT 19.04.1986    Do not worry if tabbed columns don’t line up. The distance between each of (Surname, Forename, MSc Stream and Date of Birth) column is one tab.   Question:  Why this bellow code doesn't work for me?  awk 'BEGIN {IFS=" "} {OFS="\t"} {print $1,$2,$3,$4}' students.txt Why do objects in front and back view look reversed? Whenever I model objects that has different look at front and back. Viewing it from front perspective or orthographic the model displays back of the object. XML attribute vs XML element At work we are being asked to create XML files to pass data to another offline application that will then create a second XML file to pass back in order to update some of our data. During the process we have been discussing with the team of the other application about the structure of the XML file.   The sample I came up with is essentially something like:  &lt;INVENTORY&gt;    &lt;ITEM serialNumber="something" location="something" barcode="something"&gt;       &lt;TYPE modelNumber="something" vendor="something"/&gt;     &lt;/ITEM&gt; &lt;/INVENTORY&gt;   The other team said that this was not industry standard and that attributes should only be used for meta data. They suggested:  &lt;INVENTORY&gt;    &lt;ITEM&gt;       &lt;SERIALNUMBER&gt;something&lt;/SERIALNUMBER&gt;       &lt;LOCATION&gt;something&lt;/LOCATION&gt;       &lt;BARCODE&gt;something&lt;/BARCODE&gt;       &lt;TYPE&gt;          &lt;MODELNUMBER&gt;something&lt;/MODELNUMBER&gt;          &lt;VENDOR&gt;something&lt;/VENDOR&gt;       &lt;/TYPE&gt;    &lt;/ITEM&gt; &lt;/INVENTORY&gt;   The reason I suggested the first is that the size of the file created is much smaller. There will be roughly 80000 items that will be in the file during transfer. Their suggestion in reality turns out to be three times larger than the one I suggested. I searched for the mysterious "Industry Standard" that was mentioned, but the closest I could find was that XML attributes should only be used for meta data, but said the debate was about what was actually meta data.  After the long winded explanation (sorry) how do you determine what is meta data, and when designing the structure of an XML document how should you decide when to use an attribute or an element? I've seen a lot of people talking about FPGA's before and I know that it stands for field-programmable gate array but how does it work and what is the purpose of using an FPGA? Check out the screenshot below, I want to extend my C partition (where Windows is installed) into the unallocated free space shown. This space was cleared up by shrinking the D partition. I can extend the D partition if I want to, but not the C.  Why not?