On 01/03/2011 19:10, Paul wrote:
"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:25KdnV4gcdKwovDQnZ2dnUVZ8oSdnZ2d@giganews.com...
On 01/03/2011 18:41, Paul wrote:
"Gerhard Fiedler" <gelists@gmail.com> wrote in message
news:7l4qxi2mntr9.dlg@gelists.gmail.com...
Paul wrote:
I think this proves the same point using standard C++ code:
#include <iostream>
class Animal{public:
virtual void eat(){std::cout<< "Animal Eating"<< std::endl;}
virtual int getID()=0;
static int count;
};
class Dog: public Animal{
public:
void eat(){std::cout<< "Dog Eating"<< std::endl;}
int getID(){return 1;}
};
class Cat: public Animal{
public:
void eat(){std::cout<< "Cat Eating"<< std::endl;}
int getID(){return 0;}
};
int Animal::count =10;
Dog* overwriteCat(Animal* ptr){
delete ptr;
Dog* p = reinterpret_cast<Dog*>(ptr);
p = new Dog;
return p;
}
Cat* overwriteDog(Animal* ptr){
delete ptr;
Cat* p = reinterpret_cast<Cat*>(ptr);
p = new Cat;
return p;
}
void ordinary_function(Animal* obj){
Animal::count--;
std::cout<<"Address of obj: " <<obj << " ";
obj->eat();
if(obj->getID()){overwriteDog(obj);}
else {overwriteCat(obj);}
if(Animal::count){
ordinary_function(obj);
}
}
int main()
{
Cat* p_cat = new Cat;
Animal* p_anim = p_cat;
ordinary_function(p_cat);
}
What point are you trying to prove with this code?
It proves a function can be recursed with a different object parameter
each recursion.
This cannot be done with a NSMF, thus it proves a significant
difference
between an ordinary function an a NSMF.
struct foo{
...
void wibble() {
...
foo differentObject;
differentObject.wibble();
...
}
...
};
Bad code syntax corrected ^^^^^^^^^^^^^^^^^
What bad syntax? What correction? If you are referring to your
whitespace changes then you are incorrect to call this a syntactical
change; the value of a particular whitespace format is purely
subjective as it is purely a matter of style.
Proof of your expertise on stack corruption. If this the best you can
produce, thankyou for proving me correct.
What stack corruption? Why do you think I added ellipses? The ellipses
obviously refer to code that would prevent a stack fault but such code
is orthogonal to the issue under discussion hence the use of ellipses.
You have not been proven correct; you have been repeatedly proven
incorrect. In this particular instance I have given you an example of
a NSMF being recursed with a different object which you claimed can
not be done.
As I have said please stop making a fool of yourself Leigh , I'm sick of
proving you wrong on stuff and I'm sick of your lack of reasoning and
lack of intelligent arguments.
You are describing yourself not me.
/Leigh