Is it legal code?

G

Gerhard Fiedler

Paul said:
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?

Gerhard
 
P

Paul

Gerhard Fiedler said:
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.
 
P

Paul

Leigh Johnston said:
struct foo{
...
void wibble() {
...
foo differentObject;
differentObject.wibble();
...
}
...
};
Bad code syntax corrected ^^^^^^^^^^^^^^^^^

Proof of your expertise on stack corruption. If this the best you can
produce, thankyou for proving me correct.

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.
 
P

Paul

Leigh Johnston said:
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.


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.


You are describing yourself not me.

/Leigh

I wasn't describing anybody I was explaining some of the facts that prove
you are a complete idiot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top