Click here to Skip to main content
15,899,825 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: File I/O que Pin
LiYS26-Dec-05 22:51
LiYS26-Dec-05 22:51 
GeneralRe: File I/O que Pin
Prakash Nadar27-Dec-05 0:03
Prakash Nadar27-Dec-05 0:03 
GeneralRe: File I/O que Pin
vikas amin27-Dec-05 0:43
vikas amin27-Dec-05 0:43 
AnswerRe: File I/O que Pin
Owner drawn26-Dec-05 23:22
Owner drawn26-Dec-05 23:22 
AnswerRe: File I/O que Pin
krmed27-Dec-05 4:57
krmed27-Dec-05 4:57 
QuestionHOT TO TYPE CAST OJBECT TO VARIANT Pin
gpshadrach26-Dec-05 21:45
gpshadrach26-Dec-05 21:45 
AnswerRe: HOT TO TYPE CAST OJBECT TO VARIANT Pin
AntonGogolev26-Dec-05 21:58
AntonGogolev26-Dec-05 21:58 
Questiontemplate class Pin
Nishad S26-Dec-05 21:29
Nishad S26-Dec-05 21:29 
Hi,

I created a template class, just like:
template < typename TYPE, typename TYPE_ARG = TYPE > class DataList
{
public:
    void AddNode( TYPE_ARG val_i )
    {
        // some code to handle linked list.

        SetVal( val_i, valNew );

        // some code
    }
protected:
    struct NODE
    {
        NODE* pNext;
        TYPE val;
    };
    virtual void SetVal( TYPE_ARG valSrc_i, TYPE& valDst_o )
    {
        val = val_i;
    }
};

This is only a model. I use this class for a general purpose linked list.
I derived a class for string handling, just like:
class StringDataList : public DataList < LPTSTR, LPCTSTR >
{
private:
    void SetVal( LPCTSTR valSrc_i, LPTSTR& valDst_o )
    {
        // copy the string
        valDst_o = new TCHAR[ lstrlen( valSrc_i ) ];
        lstrcpy( valDst_o, valSrc_i );
    }
};

Thus I can use the template class for both numeric data handling and string handling.
For example:
DataList < int, int > intDataList;
StringDataList strDataList;
The real problem is, we assume that the input parameters should be const, especially for pointers (that's why I use LPCTSTR as TYPE_ARG in StringDataList).
So the compiler shows error in the base class while compiling StringDataList.
The error is error C2440: '=' : cannot convert from 'const char *' to 'char *'
If I change the TYPE_ARG to TYPE in the SetVal of template class, another problem arises. That is in the AddNode. It is written as to pass the const input value to the SetVal. To clear it, I have to change the input from TYPE_ARG to TYPE. It is OK for all the classes passing value, but for string type, it is not advisable.

One solution is, I think, use type cast in SetVal, just like
val = TYPE( val_i )

Is there any other better solution?

Thank you.

- NS -
AnswerRe: template class Pin
vikas amin27-Dec-05 0:49
vikas amin27-Dec-05 0:49 
QuestionGUId of a COM object Pin
ragavan26-Dec-05 21:25
ragavan26-Dec-05 21:25 
AnswerRe: GUId of a COM object Pin
AntonGogolev26-Dec-05 22:05
AntonGogolev26-Dec-05 22:05 
Questionwarning C4509: nonstandard extension used: Pin
Chintoo72326-Dec-05 20:43
Chintoo72326-Dec-05 20:43 
AnswerRe: warning C4509: nonstandard extension used: Pin
toxcct26-Dec-05 22:49
toxcct26-Dec-05 22:49 
QuestionC\C++ with Expat Pin
praveenanil0426-Dec-05 20:06
praveenanil0426-Dec-05 20:06 
QuestionAre static members auto removed from HEAP ? Pin
Owner drawn26-Dec-05 18:01
Owner drawn26-Dec-05 18:01 
AnswerRe: Are static members auto removed from HEAP ? Pin
asdfkjsodifuweior26-Dec-05 18:34
asdfkjsodifuweior26-Dec-05 18:34 
GeneralRe: Are static members auto removed from HEAP ? Pin
vikas amin26-Dec-05 18:52
vikas amin26-Dec-05 18:52 
GeneralThen where are they allocated! Pin
Owner drawn26-Dec-05 18:57
Owner drawn26-Dec-05 18:57 
General[Message Deleted] Pin
Sheng Jiang 蒋晟26-Dec-05 19:41
Sheng Jiang 蒋晟26-Dec-05 19:41 
GeneralRe: Then where are they allocated! Pin
Owner drawn26-Dec-05 19:53
Owner drawn26-Dec-05 19:53 
General[Message Deleted] Pin
Sheng Jiang 蒋晟26-Dec-05 20:08
Sheng Jiang 蒋晟26-Dec-05 20:08 
GeneralRe: Then where are they allocated! Pin
Owner drawn26-Dec-05 20:39
Owner drawn26-Dec-05 20:39 
GeneralRe: Then where are they allocated! Pin
Sheng Jiang 蒋晟26-Dec-05 20:44
Sheng Jiang 蒋晟26-Dec-05 20:44 
GeneralRe: Then where are they allocated! Pin
asdfkjsodifuweior26-Dec-05 21:17
asdfkjsodifuweior26-Dec-05 21:17 
GeneralRe: Then where are they allocated! Pin
Prakash Nadar27-Dec-05 0:16
Prakash Nadar27-Dec-05 0:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.