Hello, I have been getting these annoying error and warning messages from the compiler that I really don't understand. Consider the following code example:
class objA
{
public:
objA(){};
~objA(){};
public:
virtual bool Setup(int){};
bool Setup(float){};
};
class objB : public objA
{
public:
objB(){};
~objB(){};
public:
virtual bool Setup(int){};
};
class C
{
public:
C(){};
~C(){};
public:
bool doTest()
{
objB b;
b.Setup(100);
b.Setup(0.0001); // warning C4244: 'argument' :
// conversion from 'const double' to 'int', possible loss of data
};
};
So here we get a warning message from the compiler as it doesn't know what function to use -- it is as if it doesn't recognise the base-class' method. I know that somehow this has to do with the virtual
keyword in use, but I really don't know why this is happening. Now consider yet another code example:
class _objA
{
public:
_objA(){};
~_objA(){};
public:
bool Setup(int){};
bool Setup(float){};
};
class _objB : public _objA
{
public:
_objB(){};
~_objB(){};
};
class _C
{
public:
_C(){};
~_C(){};
public:
bool doTest()
{
_objB _b;
\_b.Setup(100);
\_b.Setup(0.0001); // no warnings whatsoever! the compiler correctly casts!
};
};
Here we have a class being derived from another one but without any virtual methods -- no errors/warnings! Can someone please explain me what are the compiler/C++/ANSI rules I am missing here? Thank you very much, David