Thread: Templated Abstract Class...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up Templated Abstract Class...

    This is better explained in code. Suppose I have this:

    Code:
    template < typename T >
    class Foo
    {
    public:
    	T i;
    };
    
    class Bar : public Foo< int >
    {
    public:
    	int v;
    };
    Now I try to do this:

    Code:
    Foo< int > A = Bar(); // This works fine
    Foo B = Bar(); // <----------------This doesn't work!!!!
    Is there another way to do this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So how is the compiler supposed to guess what type B is?

    It knows A is related to int, through <int>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Hmm... looks like I've gotta replan this then.

    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing pointers to a templated class in a vector
    By rt454 in forum C++ Programming
    Replies: 4
    Last Post: 01-19-2009, 03:04 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Using a templated object in another class
    By harry_p in forum C++ Programming
    Replies: 3
    Last Post: 08-18-2002, 11:35 PM