Re: C++ value from union structure using generic class
- From: "Hunk" <santosh.udyavara@xxxxxxxxx>
- Date: 28 Jan 2007 22:17:15 -0800
problem, it /is/ permitted to ignore the mantra, you know!Yep think this is the way to go...cant try to do cute things to solve
problems
its a typo .. it should have been} That "<template data_type>" line is not C++ syntax, so I'm not sure
template <data_type>
class Index {
int key; // id associated with union structure
}
This is how i'm doing it presently*(reinterpret_cast<R*>(d_data.d_user_def_data)); I think you should be using a static_cast<R*> here, by the way.I personally think of the C++ foo_casts as "the one with the shorter
name is more likely to be right".
static_cast > dynamic_cast > reinterpret_cast.
You need to read what the comp.lang.c FAQ has to say about unions,Thanks for the suggestions
and then read what the comp.lang.c++ FAQ says about templates. You're
coming up with really complicated anti-solutions to problems that
should be solved quickly and easily, either with the C-style
tag-and-union I showed you already, or with
template <typename T>
struct MyCache {
T *value;
};
// plus specializations for 'int' and 'float';
// compare "std::vector<bool>" in the C++ standard
-Arthur,
"when in doubt, read the FAQ"
.
- References:
- C++ value from union structure using generic class
- From: Hunk
- Re: C++ value from union structure using generic class
- From: Arthur J. O'Dwyer
- C++ value from union structure using generic class
- Prev by Date: Re: hey help in solving the following recurrence...
- Next by Date: Re: Algorithm to find break in contiguity
- Previous by thread: Re: C++ value from union structure using generic class
- Next by thread: Recursive prime checking
- Index(es):
Relevant Pages
|