Alf P. Steinbach a ?crit :
What's all this stuff about gynecologists?
I think it's off-topic for this group.
It's just for you to understand the context
I would like to avoid to put #ifndef everywhere in my code, that's
why I wanted to make a simple class that would do the ugly job.
Actually the pointer I am interested in is a void* ie it can point to
anything BUT in the case I am assigning from a windows unicode
string (const wchar_t*) I want to do some specific action(convert
into utf8).
That also seems pretty irrelevant to your question.
So I am starting with this :
template <typename T>
class IConvPtr
{
public:
IConvPtr& IConvPtr::operator=(T* aptr)
{
m_ptr = aptr;
}
inline void* getPtr() { return m_ptr; }
private:
void* m_ptr;
};
But not sure this is a right way of doing it.
It isn't.
There's no single right way, but the above is definitely a Wrong Way(TM).
Don't have a void* pointer, don't use a template, don't use setters
and getters, and having said that, there's *nothing* relevant to your
question in that code.
So to sum up as long as assigned pointer is not a const wchar_t* I
just copy pointer otherwise I do some action.
You should post this question to a Windows-specific group, because the
easiest way to do ->UTF8 conversion in Windows is to use (I nearly
wrote sue, 'scuse me) the Windows API instead of implementing it
yourself. Implementing the conversion yourself isn't hard though. But
it's tedious, and the API may be more efficient.
The FAQ has some great suggestions for Windows-specific groups.
I am really pissed off by that kind of answers, my question is not
windows specific. I DO KNOW ho to convert from ansi to unicode this is
not the problem.
I could ask my question by rewriting terms differently without
mentionning windows type or even windows.
This is a C++ question, on windows forums they don't know how to use
advanced C++ they will answer me to use WideCharToMultiByte function.
I DONT give a fu....
So here is my question asked differently :
in C++ (I insist) is it possible to write a kind of smart pointer that
when assigned from any type just copy the pointer EXCEPT when it's a
given type (for instance chat*).
something that would allow me to write :
IConvPtr iconvptr;
...
switch(ulPropType)
{
case TYPE_INT: { iconvPtr = &(lpProp->val.iValue); break; }
case TYPE_FLOAT: { iconvPtr = &(lpProp->val.fValue); break; }
case TYPE_STRING: { iconvPtr = &(lpProp->val.szValue); break; }
...
}
iconvPtr.getPtr()
so now don't tell me it's windows specific, ulProptype is a unsigned
long that tell me the type of the pointed value.
So what I want to know if it's possible to have a IConvPtr object that
could be assigned any kind of pointer and that would allow to have a
custom action when assigning from a const char*.
Do I need to write a assignement overload for every type that can be
assigned ?
Could templated class could be of any help ?
code for each type I am assiging...