LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2008, 10:44 AM   #1
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Rep: Reputation: 16
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
 
Old 07-06-2008, 12:01 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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;
}
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
for your reference!! alicehuang General 0 01-25-2006 03:30 AM
need some reference Hamid Moradmand Programming 0 05-17-2004 12:46 AM
C++ Reference qcoder Programming 6 01-13-2004 02:22 AM
conversion to non-const reference type max2878 Linux - General 2 05-23-2002 01:25 PM
c/c++ reference balfred Programming 1 05-10-2002 12:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration