Thread: Generic Template Pointer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Generic Template Pointer

    Okay, now I've got a real brain blender...

    I've got a base class: A
    There are two derived classes: B, C

    B is a template for any derived type of C.
    C is an ADT that needs a data member that is a pointer to a B. Therein lies my trouble. Such a thing is circular, so how can it be done?

    Let me illustrate:
    Code:
    class A {
    };
    
    template <typename T>
    class B : public A {
    };
    
    class C : public A {
      B<C> *pointerToB;// B<C2>* would work, but C2 is user-defined
      void foo() = 0;// for clarity
    };
    
    //
    // user's code follows
    //
    class C2 : public C {
      void foo() { }
    };
    
    class B2 : public B<C2> {
    };
    I cannot create the variable pointerToB because I need to specify the template parameter for B, but I cannot do that because that class is defined by the user (derived from C).

    This is either a strange problem that has an easy fix one of you knows about or it's a very poorly designed set of classes.

    I guess if all else fails I can just make the pure virtual functions stop being pure virtual, but hopefully there is another solution.
    Last edited by LuckY; 10-19-2004 at 04:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 10:17 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM