I have an assignment that demands I use a copy constructor. So let's say we have the following code:  class Animal   /*abstract class*/ { private:     string name;     int age; public:     Animal();     ~Animal();     virtual int is_bad() = 0; }  class Dog : public Animal { public:     Dog();     ~Dog();     int is_bad() {         return 0;     } }  /*constructors*/  Animal::Animal(int age,string name) {     this-&gt;age=age;     this-&gt;name=name; }  Dog::Dog(int age, string name) : Animal(age,name) {     cout &lt;&lt; "Woof" &lt;&lt; endl; }  /*main*/  int main() {     Animal * c;      c = new Dog(10,"rex");      return 0; }   So my question is as follows. If I want to make a copy constructor that makes a duplicate of dog for example Dog(const Dog &amp; d), what do I need to add to my code and how do I call it in my main function? I'm a newbie so I'll need a quite elaborated answer.
As Scott Myers wrote, you can take advantage of a relaxation in C++'s type-system to declare clone() to return a pointer to the actual type being declared:  class Base {     virtual Base* clone() const = 0; };  class Derived : public Base {     virtual Derived* clone() const };   The compiler detects that clone() returns an pointer to the type of the object, and allows Derived to override it to return a pointer to derived.  It would desirable to have clone() return a smart pointer that implies transfer of ownership semantics, like the following:  class Base {    virtual std::auto_ptr&lt;Base&gt; clone() const = 0; };  class Derived : public Base {     virtual std::auto_ptr&lt;Derived&gt; clone() const; };   Unfortunately, the relaxation of the conventions does not apply to templated smart pointers, and the compiler will not allow the override.  So, it seems I am left with two options:   Have clone() return a "dumb" pointer, and document that clients are responsible for disposing of it. Have clone() return a smart base pointer, and have clients use dynamic_cast to save them to a Derived pointer if they need it.   Is one of these approaches preferred?  Or is there a way for me to eat my transfer of ownership semantics and have my strong type safety too?
I want to be able to  write the following in LaTeX      We make the further assumption that \begin{equation} \label{eqn:assumption} There is a bounded linear operator     $B:X\to X^*$ such that $B^*=B$ and the operator $JB$ is an extension of $T'(0)$\end{equation}   and get a nice output, in such a way that this whole chunk of text along with the math can be referenced later. Of course I can write text inside the equation environment using \text{}, but when I tried this the spacing was all wrong. Can anyone suggest a solution to this? In Back to the Future, how did Marty get the timing right with the lightning strike? So, in the first movie, presumably the Doc and Marty know exactly when the lightning will strike the clock tower. This is because Marty has the flyer with the picture of the stopped clock on it. In order to power the DeLorean, the Doc cooks up this contraption to conduct the lightning through a hook into the DeLorean. All Marty has to do is be driving at 88 mph and hit the wire at the exact right moment.  Here's the question though - if you recall, the Doc sets a timer and tells Marty to drive back to a pre-designated starting point. When the timer goes off, Marty is supposed to accelerate to 88 mph. My assumption is that the Doc has calculated the maximum acceleration of the DeLorean, and using this value has determined the exact starting point that the car needs to be at in order to hit the lightning at the right time.  Unfortunately, the car stalls. It takes Marty a while, but he's finally able to start it up. Being that he started late though...shouldn't he have missed the lighting? What is the point of stacking favorite notifications? Topology: Proof that a finitely generated cone is closed Otherwise, is there any alternative command line utility that can achieve this? How to draw good arrows explaining parts of equation? Example of modules that are projective but not free; torsion-free but not free I'm taking Calculus II next semester so I don't have all the tools from it to back me up but something came up in a discussion this evening that asked me to prove that the following sequence converges. As I'm new to formal math I'm hoping someone can verify my proof, especially step $6$. I must prove that $$\lim_{n\to\infty}P_n=b$$ where $$P_{n+1} = P_n + \frac{b-P_n}{2}$$ $$P_0 = a$$ and $a,b \in \mathbb{R}$ such that $a&gt;b$ My proof goes as follows:   We must prove that $$\lim_{n\to\infty}P_n=b$$  That is, $\forall\epsilon&gt;0$ there exists a $\delta$ such that there exists an $n$ satisfying $$n&gt;\delta \iff b-P_n&lt;\epsilon$$  First, let us prove that $P_n$ is bounded by $b$ by contradiction. Let us choose an $i$ such that $P_i &lt; b$ and $P_{i+1}&gt;b$. Then we have $P_{i+1} = P_i + \Delta P$ where $\Delta P &gt; b-P_i$. but this is impossible because by the definition of the recurrence $\Delta P = \frac{b-P_i}{2} &lt; b-P_i$. Therefore, $P_i$ is bounded from above by $b$.  Additionally, it is trivial to show that $P_{i+1} &gt; P_i$.  With this in mind, choose an arbitrary $\epsilon$. We need to show that there exists an $n$ such that $P_n &gt; b-\epsilon$. Assume the contrary, that $P_n$ is bounded by $\epsilon$.  Using a similar argument to what which was used before, assume $P_n$ is bounded by $\epsilon$ and then there exists a $P_i$ such that $P_{i+1}\not &gt; P_i$. But this results in a contradiction with (4)  Therefore, $P_n$ is not bounded by $\epsilon$ and we have proved what we want to prove. Find all files that are NOT of a specific type/extension in folder? How do I determine the size of my array in C?   That is, the number of elements the array can hold? How do you attach a debugger to a Web service? I am using a Web service. Can anybody tell me how to debug through it? Helix in a helix I am trying to work out a "helix in a helix" mathematically.  Intuitively I think of this as a steel cable, which is made up of a number of smaller steel cables all bound together in spiral.  If I wanted to find the length of one of the individual cables, it would be bound in a spiral in the smaller cable and then those cables bound in a larger spiral cable.  I know that if I wanted to do a helix whose ends meet, I would use the parametrization $$((a+b\cos(\omega{t}))\cos{t},(a+b\cos(\omega{t})\sin{t},b\sin(\omega{t})),t=0..2\pi$$ I've been trying to map out in my head how to, instead of curling the helix, making the helix travel in the path of a helix.  I've achieved it partially with $$((a+b\cos(\omega{t}))\cos{t},(a+b\cos(\omega{t})\sin{t},t),t=0..\infty$$ But this doesn't keep the smaller helix in tact, and turns it into a sine wave helix.  I've also tried  $$((a+b\cos(\omega{t}))\cos{t},(a+b\cos(\omega{t})\sin{t},tb\sin(\omega{t})),t=0..2\pi$$ But this gives me sort of a nautilus shape where the helix curls into itself and increases in size and curls around into itself.  What am I missing?  EDIT:  Also, what if we wanted to do this again, like a 'helix in a helix in a ... in a helix'? Automating DB Restore from network share Where are my Minecraft saves located? I want to copy/modify/delete a Minecraft world. Where can I find my saves folder? Who did Khan get his Starfleet insignia from? We have a view for a type of node that includes a Private File.  We cannot see a way to add an exposed filter, such as "Contains any word", and have it filter based on the file's name.  Are we missing something obvious? How can I bring STAG back if I have 100% completion? There's a couple of the Saintsbook challenges that require you to have STAG forces available to kill.  After you complete the game, however, the STAG forces are nowhere to be found.  I believe that you can fight a few more STAG forces if you replay the final mission, but I think my save is glitched, so that's not an option.    Is there any way post-game completion to bring STAG back?  I miss their much nicer tanks and VTOLs for hijacking :( I'm running Bash scripting, but sometimes I get confused which of these commands I use belong to who. Sometimes man xxx works, sometimes doesn't, so I use --help or info, mostly one of these works to show description of the command. Can anyone tell me how I would know what command belongs to what? Bash builtin, GNU utility, etc. Fan is always on, CPU usage is rather low and can't find the fan or thermal_zone proc files I have an Asus N76VB notebook with Ubuntu 14.04 and TLP for power managment. However, the fan is always on. It's not really loud, but it's annoying. My CPU usage is around 1-2%. It's clocked at 1.20 GHz.  I've added acpi=force to my boot parameters but it doesn't change anything.  /proc/acpi/fan: No such file or directory /proc/acpi/thermal_zone: No such file or directory   I've loaded all Asus ACPI modules.  lsmod | grep asus:  asus_nb_wmi            16990  0  asus_wmi               24191  1 asus_nb_wmi sparse_keymap          13948  1 asus_wmi video                  19476  2 i915,asus_wmi wmi                    19177  2 mxm_wmi,asus_wmi   Somehow, it can read the temperatures.  sensors:  acpitz-virtual-0 Adapter: Virtual device temp1:        +43.0°C  (crit = +108.0°C)  coretemp-isa-0000 Adapter: ISA adapter Physical id 0:  +44.0°C  (high = +87.0°C, crit = +105.0°C) Core 0:         +44.0°C  (high = +87.0°C, crit = +105.0°C) Core 1:         +42.0°C  (high = +87.0°C, crit = +105.0°C) Core 2:         +39.0°C  (high = +87.0°C, crit = +105.0°C) Core 3:         +39.0°C  (high = +87.0°C, crit = +105.0°C)  asus-isa-0000 Adapter: ISA adapter temp1:        +43.0°C     I really hope someone knows how to solve this. Almost all information I could find was about saving power to create less heat.    I got Intel and NVIDIA (GeForce 740M) graphics but I'm almost anytime on Intel.  $ sudo lshw -c display   *-display                       description: VGA compatible controller        product: 3rd Gen Core processor Graphics Controller        vendor: Intel Corporation        physical id: 2        bus info: pci@0000:00:02.0        version: 09        width: 64 bits        clock: 33MHz        capabilities: msi pm vga_controller bus_master cap_list rom        configuration: driver=i915 latency=0        resources: irq:43 memory:f7400000-f77fffff memory:d0000000-dfffffff ioport:f000(size=64)     fwts fan: I feel like someone made a comment as an answer on a question with a bounty just so they could reap the "auto bounty" since they are the only answer on it.   I've flagged the bad/useless answer (as a non-answer) for moderator review but the bounty will be assigned automatically in less than 24hrs and I feel like this guy/gal is just trying to cheat the system.   All I'm trying to do is ensure the bounty simply expires and the guy/gal that was trying to cheat the system by putting down a useless guess doesn't get it.   I've answered my own question (properly) and marked it as the accepted answer, not sure if that makes a difference though in this person still cheating the system since I'm the OP and created the accepted answer.   Here is the post: