By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,501 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,501 IT Pros & Developers. It's quick & easy.

casting template using const_cast

P: n/a
I have a template class like below.
template <TInt Sclass XYZ
{

}

const XYZ<10abc; //Instance of the class

How do remove the constantness of abc using const_cast. I mean, I want
the syntax for that. Something like const_cast<XYZ<10>abc gives
compiler error.
Nov 7 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 11月7日, 下午10时01分, puru <purushotta...@gmail..comwrote:
I have a template class like below.
template <TInt Sclass XYZ
{

}

const XYZ<10abc; //Instance of the class

How do remove the constantness of abc using const_cast. I mean, I want
the syntax for that. Something like const_cast<XYZ<10>abc gives
compiler error.
const_cast can only do with pointer, reference and pointer to
member(function).

try this

XYZ<10>* p = const_cast<XYZ<10>*>(&abc);

--
Best Regards
Barry
Nov 7 '08 #2

P: n/a
On 7 Nov., 15:01, puru <purushotta...@gmail.comwrote:
I have a template class like below.
template <TInt Sclass XYZ
{

}

const XYZ<10abc; *//Instance of the class

How do remove the constantness of abc using const_cast. I mean, I want
the syntax for that. Something like const_cast<XYZ<10>abc gives
compiler error.
Others have explained how, but I believe having to cast is a design
error. Instead of casting yourself out of your errors, you should
correct the design, which in the long run is going to save you time
and trouble.

/Peter
Nov 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.