Inheritance
-
Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following 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 };
};
Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David
-
Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following 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 };
};
Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David
-
Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following 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 };
};
Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David
Since the 0.0001 is set-up as a const double type by the compiler, it is going to have to cast it since you have not provided an explicit cast. I'm not familiar with all the rules each compiler will use in order to decide what cast to use, but at least you are given a warning about the cast. Have you tried this
b.Setup((double)0.0001);
Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]