Templated Abstract Class...

This is a discussion on Templated Abstract Class... within the C++ Programming forums, part of the General Programming Boards category; This is better explained in code. Suppose I have this: Code: template < typename T > class Foo { public: ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 02:04 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04: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
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21