LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   conversion to a reference warning...... (https://www.linuxquestions.org/questions/programming-9/conversion-to-a-reference-warning-653896/)

HarryBoy 07-06-2008 10:44 AM

conversion to a reference warning......
 
Hi, I have a sample app which was written for MFC but I now have to convert the code to unix.

I have a class called Range which is derived from a structure RANGE :
Code:

typedef struct _tag_RANGE
{
        ANGLE start;
        ANGLE size;
        //ANGLE max;
} RANGE;

There is an operator in class Range defined as:

Code:

public:
//operators
operator RANGE& () { return dynamic_cast<RANGE&>(*this); };

When I build my app I get a warning:
Quote:

Range.h:108: warning: conversion to a reference to a base class will never use a type conversion operator
How can I get rid of this warning and it would be great if someone could explain why it is happening?

Thanks

dmail 07-06-2008 12:01 PM

Quote:

Range.h:108: warning: conversion to a reference to a base class will never use a type conversion operator
The compiler is correct, the conversion is implicit therefore making the operator redundant.
Quote:

How can I get rid of this warning
Really simply remove the operator :)

See below for example
Code:

typedef int ANGLE;
struct RANGE
{
        RANGE(ANGLE const& s,ANGLE const& sz):start(s),size(sz){}
        ANGLE start;
        ANGLE size;
};

struct Range : public RANGE
{
        Range(ANGLE const& s,ANGLE const& sz):RANGE(s,sz){}
};

#include <iostream>
int main()
{
        Range r(1,2);
        RANGE& rr(r);
        std::cout <<rr.start <<" " <<rr.size <<std::endl;
}
}



All times are GMT -5. The time now is 04:23 PM.