CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: how to use Templates in VC++

    True Kevin. I was just clarifying.

    Rats, stupid comment again ! Of course that was overloading... I really should read my posts before clicking the "add post" button.

    Darwen.
    Last edited by darwen; July 22nd, 2005 at 05:01 PM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  2. #17
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245

    Re: how to use Templates in VC++

    It happens to all of us!
    Kevin Hall

  3. #18
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: how to use Templates in VC++

    Quote Originally Posted by KevinHall
    The strategy pattern assumes that all algorithms have the same interface, which in this case, they do not. I think simple function overloading would suffice here. Nothing complicated is really needed.
    I was sure someone will come to this conclusion.
    Code:
    struct ParamBase
    {
      virtual ~ParamBase();
    };
    
    struct CharParam: public ParamBase
    {
      char *buffer;
      int size;
      // whatever else needed
    };
    
    struct UCharParam: public ParamBase
    {
      unsigned char *buffer;
      int size;
      // whatever else needed
    };
    
    struct UShortParam: public ParamBase
    {
      unsigned short *buffer;
      int size;
      // whatever else needed
    };
    
    class StrategyConverter
    {
    public:
      bool Convert(ParamBase* param1, ParamBase* param2);
    };
    
    class Char2UShortConverter
    {
    public:
      bool Convert(ParamBase* param1, ParamBase* param2)
      {
        CharParam* p1 = (CharParam*)param1;
        UShortParam* p2 = (UShortParam*)param2;
    
        // perform the conversion
      }
    };
    
    int main()
    {
      CharParam *param1 = new CharParam(...); // fill with appropriate data
      UShortParam *param2 = new UShortParam(...); // fill with appropriate data
      
      StrategyConverter *conv = new Char2UShortConverter();
    
      conv->Convert(param1, param2);
    
      delete param1;
      delete param2;
      delete conv;
    
      return 0;
    }
    It's 3:30 AM here, so I hope I did not make any mistake...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #19
    Join Date
    May 2005
    Posts
    47

    Question Re: how to use Templates in VC++

    Quote Originally Posted by darwen
    You can't really do this using templates. Or at least not easily : or nicely.
    That way of explaining don't you see is completely non-sense ?
    I am not talking about word, or grammar processing but about logical reasoning instead. Sounds like a fortune teller.
    Quote Originally Posted by darwen
    For instance the code needed to change a LPCSTR to a LPWSTR (wide string array) is different for the code to change a LPCSTR to a BSTR.
    Darwen.
    you already wrote a class with static void convert functions, now may i ask if you could post the code perhaps one of the functions you mentioned if possible to show their changes anyway ?
    Quote Originally Posted by darwen
    But that's because C# is a true object oriented language, and C++ is not - i.e. in C# everything is an object, whereas in C++ this isn't the case.

    Darwen.
    Oh, Jesux Christ, the terms you use remind me of teh days when C# was first invented by MS to compete with Sun's java after a famous trial I guess all of us know well, surely also with the intention that it was going to be another OOL but have you ever wondered if it is really true or still untrue in some aspects ?True OOL, so fast is your conclusion i mean...

    --Oh my (NO GOD)! <grabber>


  5. #20
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245

    Re: how to use Templates in VC++

    Cilu,

    I see what you're doing. However, you must admitt that unless there is some other compelling reason to create ParamBase and associated classes, that the heirachy and strategy pattern are overly complex to solve a problem that could otherwise be more easily solved with simple overloading. I mean, why complicate things with a class heirarchy, virtual function calls, and calls to new and delete? All this seems to add a lot of unnecessary overhead in my opinion.

    - Kevin
    Kevin Hall

  6. #21
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: how to use Templates in VC++

    Quote Originally Posted by KevinHall
    I see what you're doing. However, you must admitt that unless there is some other compelling reason to create ParamBase and associated classes, that the heirachy and strategy pattern are overly complex to solve a problem that could otherwise be more easily solved with simple overloading. I mean, why complicate things with a class heirarchy, virtual function calls, and calls to new and delete? All this seems to add a lot of unnecessary overhead in my opinion.
    I won't argue with that. I didn't say it's the best solution. I said it's a solution, that should be considered. And I've shown how it can be done. That's all.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  7. #22
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245

    Re: how to use Templates in VC++

    Ok!

    So, the conclusion of the matter is that simple overloading is the most straight-forward solution for this problem if taken in isolation. However, if there exists other related problems in your application, there are other possible solutions that may make sense to help tie the different concepts together. The strategy pattern is one of these possible solutions.

    - Kevin

    Remember, don't use a sledge-hammer to make a square peg fit into a round hole!
    Kevin Hall

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured