[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I'm back



Christian Reiniger wrote:
>>Send me the little tests and I'll be able to confirm that it works
>>properly.
>
>A very primitive one is attached. The output should read

Ooops, sorry. Here it is ;)

	Christian
--

Drive A: not responding...Formatting C: instead

#include <iostream>

class A
{
private:
	int i;

public:
	A (void) { i = 0; }

	virtual void Inc (void) { i++; }
	virtual int  Get (void) { return i; }
};


class B : public A
{
private:
	int j;
public:
	B (void) { j = 10; }

	virtual void Inc (void) { j += 2; }
	virtual int  Get (void) { return j; }
};


int main (void)
{
	A ClassA;
	B ClassB;

	A *APtr = &ClassA;

	if (dynamic_cast<A *> (APtr) != 0)
		cout << "APtr is of type A";
	else
		cout << "APtr is not of type A";

	cout << endl;

	APtr = &ClassB;

	if (dynamic_cast<B *> (APtr) != 0)
		cout << "APtr is of type B";
	else
		cout << "APtr is not of type B";

	cout << endl;

	return 0;
}