CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #5

    Re: Avoiding virtual method in template subclass?

    Because of performance and about 2 million other reasons. I don't mind virtual methods but it would be a big mistake here.

    Not sure there are any better options for me, though. The suggested solution is a possibility but it's a little complex. Like I said it's two one line methods I want to change, but if I did it that way I'd need to change every place I call those two methods and doing that everywhere will make an unreadable mess.

    I may as well spell out the whole problem. I have a vector class, and I want to have it so that it can either use the default allocation or it can use a different allocation method for when it's being used as a system object. However, I don't want things to get too complex, and I don't want to add in extra performance penalties, and I especially don't want its usage to change (ie extra unwieldly syntax every time you create something).

    I guess the options are:
    1. Preprocessor. Kind of ugly, but I can generate out a duplicate with small changes using preprocessor.
    2. File generation. I hate doing this, but it does work.
    3. Allocator helper object. Then I have to pass one in somehow, and I just transfer the problem of virtualness. Virtual inline static methods are almost guaranteed to make the compiler go crazy. Or else I have a few static concrete allocator objects, which I have to ensure get initialized before anything else.
    4. function pointers. No inlining for certain, then, but at least will work.
    5. CRT - kind of like 3, I guess.
    6. boolean? I can't use a switch it boils down to same problem with needing to be virtual, but I can stick a boolean in, though it increases class size.
    7. something else?
    Last edited by originalfamousjohnsmith; November 24th, 2009 at 02:44 AM.

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