Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-01-2009
Member
 
Join Date: Nov 2008
Posts: 26
How to make the operator of the type of transformation?

Hello, freinds

We should do the conversion of one type to another. If it is possible to modify the class to which drive, then so

Quote:
class CDest (
CDest (const CSrc & src) ...
If it is possible to modify the class, which included, then so

Quote:
class CSrc (
operator CDst () ...
If it is not possible to modify any of these classes, is it possible to organize the implicit conversion?
Reply With Quote
  #2  
Old 13-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: How to make the operator of the type of transformation?

Hello, you wrote:

Quote:
If you are not able to modify any of these classes, is it possible to organize the implicit conversion?
You can write its own specialization to boost:: lexical_cast. Such a transformation would not be implicit, but it will be packed in more or less a standard scheme.
Reply With Quote
  #3  
Old 13-01-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: How to make the operator of the type of transformation?

Hello, Marty, you wrote:

Quote:
If you are not able to modify any of these classes, is it possible to organize the implicit conversion?
All that comes to mind is:

Quote:
struct TempSrc
(
private:
CSrc m_src;
TempSrc ()
(
)
public:
TempSrc (const CSrc & s_)
(
m_src = s_;
)
operator CDest ()
(
CDest dest;
dest.val = m_src.val;
dest.val1 = m_src.val1;
return &dest;
)
);
But the implicit conversion will fail, because the level of nesting should not be more than one.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 13-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: How to make the operator of the type of transformation?

It is believed that the implicit transformation should be avoided. you Do not tell why you took this transformation?
Reply With Quote
  #5  
Old 13-01-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: How to make the operator of the type of transformation?

Quote:
Originally Posted by Reegan View Post
It is believed that the implicit transformation should be avoided. you Do not tell why you took this transformation?
There is a POD type of line used for the transmission line between binary modules, I want to convert it without extra writings in the std:: string.
Reply With Quote
  #6  
Old 13-01-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to make the operator of the type of transformation?

Why implicitly?

Quote:
accept (MyCustom_cast <TOut> (in));
- And management and clearly write only for specialization TOut MyCustom_cast <TOut, TIn> (const TIn &);

or like this

Quote:
/ / converter by default assumes that the type From appears to have normal To
template <class From, class To>
To customCastCnvt (const From & from)
(
return from;
)

////////////////////////////////////////////////// ////////////////////////
/ / layer, a reference to the retention of existing templates and From the operator to bring, is used customCastCnvt
template <class From>
struct CustomCastHolder
(
const From & _from;
CustomCastHolder (const From & from)
: _from (From)
(
)

template <class To>
operator To ()
(
return customCastCnvt <From, To> (_from);
)
);

////////////////////////////////////////////////// ////////////////////////
/ / interface function creates layer
template <class From>
CustomCastHolder <From> customCast (const From & from)
(
return CustomCastHolder <From> (from);
)

////////////////////////////////////////////////// ////////////////////////
/ / types of workers
struct D
(
int ind;
);
struct A
(
int ina;
operator D () const
(
D tmp = (ina);
return tmp;
)
);

struct B
(
int inb;
);
struct C
(
int inc;
C (const A & a)
: Inc (a.ina)
(

)
);


////////////////////////////////////////////////// ////////////////////////
/ / specialization of transformation for A => B
template <>
B customCastCnvt <A, B> (const A & from)
(
B tmp = (from.ina);
return tmp;
)

int main (int argc, char * argv [])
(
A a;
B b = customCast (a); / / customCastCnvt <A, B>
C c = customCast (a); / / C:: C (const A &)
D d = customCast (a); / / A:: operator D
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to make the operator of the type of transformation?"
Thread Thread Starter Forum Replies Last Post
XP to Windows 7 Transformation Pack SEGONTIUM Windows XP Support 1 11-05-2011 11:57 AM
Content Type | Mime Type for Office 2010 file format and extension ramsun Tips & Tweaks 1 16-08-2010 05:25 PM
Content Type | Mime Type for Office 2007 file format and extension D_chapple Tips & Tweaks 1 16-08-2010 04:44 PM
Best OS X Transformation Pack advsnhal Customize Desktop 4 16-04-2009 09:52 AM
How to make the XML to XHTML Transformation DayanandPatil Software Development 3 02-02-2009 12:23 PM


All times are GMT +5.5. The time now is 10:39 PM.