Note:  I do not agree this is a duplicate of the linked issue.  While that is an issue, that is not the question.  Please see below.  When I assign a new class instance to an array, the base class' virtual function  is used instead of the overridden derived class virtual function.  I was told the problem with the code below is .  However, according to , this should work.  I am a beginner at C++, so I'm not sure who is right.  Can someone point me in the right direction or tell me what's wrong?  Is this because I'm copying the object to the array instead of "pointing" to it?  However, I can't figure out how to do this correctly.  See code below for what I've tried.  Addendum:  There is in fact an object slicing problem here.  However, the purpose of my question and what I did not understand is that overriding only works if you use pointers or an array of pointers and not if you declare an array of instances.  #include &lt;iostream&gt;  // I know these should be structs since they're all public! class Animal {   public:     Animal() { std::cout &lt;&lt; "Animal constructor\n"; }     virtual void speak() { std::cout &lt;&lt; "Animal/Hello!\n"; } };  class Dog: public Animal {   public:     Dog() { std::cout &lt;&lt; "Dog constructor\n"; }     void speak() override { std::cout &lt;&lt; "Dog/Bark!\n"; } };  int main() {   const int Size = 4;    Animal* Kingdom = new Animal[Size];   Dog* rover = new Dog;    // Legal because of polymorphism:   Animal* spot = new Dog;    // Legal because of polymorphism;   // Believe this is wrong - I think I'm copying the value rather than   // pointing to it, but not sure what the right way is...   Kingdom[0] = *(new Dog);   // &amp;Kingdom[0] = new Dog;  // Error - left operand must be l-value   // Kingdom = new Dog;  // Wrong - changing array base, leaking memory    Kingdom[1] = *rover;   Kingdom[2] = *spot;    // Virtual method followed here:   std::cout &lt;&lt; "\nIndividual invocations:\n";   rover-&gt;speak();   spot-&gt;speak();    std::cout &lt;&lt; "\nInvocation from array:\n";   for (int i = 0; i &lt; Size; ++i)     // Doesn't work - virtual method not followed, not sure why...     // Kingdom[i].speak();     // No difference between these two forms:     (Kingdom + i)-&gt;speak();    // PS - I know I should put deletes in here not to leak memory! }
Someone mentioned it in the IRC as the slicing problem.
Why is there a peeking duck in my profile pic? In , you may see something odd: a peeking duck.    I've just recently uploaded this new profile picture of mine. I checked it after the upload and everything's fine. After a few hours, I opened my profile and there it is, the duck has somehow become afraid of the people viewing it.  Is this a bug, a feature, or is it just the duck?  I am about to re-upload my profile pic, but I've decided to drop first this topic to meta.  And if you're curious,  is the original picture.    ADDITIONAL: I've used the non-gravatar way to upload the picture.  ADDITIONAL 2: The problem only shows in the profile view. No problem in chat, less info profile view, and in the questions and answers.  UPDATE: Re-uploaded picture. Status normal (for now, at least). I'm a 16-year-old male, and I have been interested in tabletop RPGs for a long time, especially D&amp;D. I sorta dove into D&amp;D really fast and hard by buying the Red box, Dungeon Master Kit, Monsters Vault, Players Handbook, Rules book, and even the Shadowfell Campaign not quite knowing what I'd get myself into. I've done tooonnsss of research and even watched live games on Youtube.   For the most part, I'm basically on my own, My friends are somewhat interested in it and want to play, but expect me to Teach/Dungeon Master the game for them, I'd really wish to do this, but need more insight and expertise. I've played the solo Campaign in the Red box and even thought about joining a local group from a popular gaming store in Phoenix, AZ called Imperial Outpost. But I'm not sure if they would take a newbie like myself. Any advice? What are Alternative's "some" and "many" useful for? This is exercise 1.6.1 of   Suppose that 501 distinct integers are selected from 1 . . . 1000. Show that there are distinct selected integers $a$ and $b$ such that $a | b$. Show that this is not always true if 500 integers are selected.  This seems like it should be simple but it's has been stumping me for a few days.  Here's my idea for a proof:  Let $S$ be a set of 500 distinct integers between 1 and 1000 that don't divide each other. Let $S_{1-500}$ and $S_{501-1000}$ partition $S$ into sets containing the elements ≤ and > than 500, respectively. Then consider $2 S_{1-500}$ and $\frac{1}{2}S_{501-1000}$, the result of multiplying the elements of these sets by 2 and 1/2, respectively. Because elements of S are coprime, $S_{1-500}$, $S_{501-1000}$, $2 S_{1-500}$, and $\frac{1}{2}S_{501-1000}$, are disjoint. Also note that each of these sets is a subset of the integers from 1 to 1000. One can deduce that the cardinality of the union of these sets is 1000, and therefore they form a partition of the integers from 1 to 1000.  Now, I know this demonstrates that you can't add another number to $S$ that is coprime with all the elements in $S$, which means that a coprime subset of the integers from 1 to 1000 can have at most 500 elements. Can someone articulate why this is true for me? Also, this was in a section on the Pigeonhole principle, can someone rework the proof to utilize that, and possibly make it simpler? Thanks. Create a local texmf tree in MiKTeX Biasing circuit - Voltage follower circuit Curve Bevel function, scale? Is there a way to scale up the bevel object on one end of a curve, a little bit over each point?  I notice the vertex "weight" slider will tweak how much influence each vertex has on the others, is there something like this that can scale the bevel object up a little bit?  Preferably with the option to constrain X,Y,Z independently Why does Ubuntu fail to run .exe files? / How do I run .exe? Object of class mysqli_result could not be converted to string This is a basic question on Box-Jenkins MA models. As I understand, an MA model is basically a linear regression of time-series values $Y$ against previous error terms $e_t,..., e_{t-n}$. That is, the observation $Y$ is first regressed against its previous values $Y_{t-1}, ..., Y_{t-n}$ and then one or more $Y - \hat{Y}$ values are used as the error terms for the MA model.  But how are the error terms calculated in an ARIMA(0, 0, 2) model? If the MA model is used without an autoregressive part and thus no estimated value, how can I possibly have an error term? Clear 301-redirect cache in Firefox Is it possible to clear only 301-redirects from Firefox's cache? CTRL+F5 doesn't do the job since you just reload the target without caching but do not clear the cached redirect.  An option to disable caching of those redirects completely would be fine, too - but some way (possibly through an extension) to remove those cached redirects would be better.  Note: I'm not looking for answers that disable all caching (including CSS, JS, etc.) How to animate morphing a rectangular plane into a sphere My public website name and AD domain name are the same. How can I get to my external website from inside my network? How do I add a kernel boot parameter? I need to add the boot parameter foo=bar to my kernel. How can I do this once for testing, and permanently if testing was a success? In the comment field on StackOverflow (and other StackExchange sites as well, I presume) you're required to write 15 characters for the server to accept your post. If a shorter post is submitted, an information message states that the comment is too short. That is all good.  However, below the comment field is a counter, which counts up to 15 and then down from however many characters you're allowed to type minus fifteen. This counter doesn't always act the same as the actual validation: if I pad my message with whitespace, the validation notices and still says the message is too short, but the counter does not notice, and counts as usual.  Suggested fix: make the character counter trim the message before it counts, so the two messages say the same thing. The infinite product of the sines of all positive integers is zero I tried to prove that $\prod\limits_{k = 1}^\infty  {\sin k = 0}$  Define $$P(m)=\prod\limits_{k = 1}^m  {\left|\sin k\right|}$$  then I take the logarithm of both sides $$\log P(m)=\log \prod\limits_{k = 1}^m  {\left|\sin k\right|}$$  which can be written as $$a_m=\log P(m)=\sum\limits_{k = 1}^m  {\log\,\left|\sin k\right|}$$ for any $k\in\mathbb{N}$ we have $0&lt;\left|\sin k\right|&lt;1$, so all terms of the sum above is strictly negative.  I say that the sequence diverges: $\left\{a_m\right\}_{m\in\mathbb{N}}\to\,-\infty$  This is a delicate point on which I have some doubts.  I know that  $$\int\limits_0^\pi  {\log \left|\sin x\right|{\text{ d}}x}  =  - \pi \log 2$$ and that the function $\log \left|\sin x\right|$ is periodic with period $\pi$,  so the integral from 1 to $\infty$ diverges to $- \infty$. Then the series diverges as well for the integral test for convergence.  As $\log P(m)\to\, -\infty$ we can say that $P(m)\to\,0$ as $m\to\,\infty$  Therefore $$\mathop {\lim }\limits_{m \to \infty } \prod\limits_{k = 1}^m {\left| {\sin k} \right| = \mathop {\lim }\limits_{m \to \infty } \prod\limits_{k = 1}^m {\sin k = \prod\limits_{k = 1}^\infty  {\sin k = } 0} }.\quad \blacksquare$$ We can easily find out if the vectors are dependent or not by finding determinant of matrices formed from the vectors. But if the matrix is not a square matrix, we cannot find the determinant. Then how do we know if the vectors are linearly independent? How do you check for whether a device is in a wifi deadzone? Why are some faces in my mesh darker? While rendering a mesh with smooth shading on, I get a dark region/shadow on certain faces. The effect is more evident when smooth shading is applied to a mesh containing ngons, with the ngons turning black when rendered.   The blackening effect is visible in the viewport too.  How can I solve this problem? How to get a function name as a string? In Python, how do I get a function name as a string, without calling the function?  def my_function():     pass  print get_function_name_as_string(my_function) # my_function is not in quotes   should output "my_function".  Is such function available in Python? If not, any ideas on how to implement get_function_name_as_string, in Python?