![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2007
Posts: 24
Rep Power: 0
![]() |
template specialization problem
Hello
I would like to do: Code: std::list<some_templated_class> _list; _list.push_back(some_templated_class<some_object>(arguments)); but my compiler wont allow me to compile this. I get error: unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type Is there any other way to be able to do/override this? Thanks for help |
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
I'm pretty sure you have to specify the template specialization of the class your list is holding when you declare it.
For example, instead of std::list<Foo> _list; You should write: std::list<Foo<int> > _list; That would be my guess anyway. ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2007
Posts: 24
Rep Power: 0
![]() |
Yeah but what if I dont know I want different types, not just int?
Maybe boost::any, boost::variant of anyone knows of better approach? |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
The you should use a common base class like so:
cpp Syntax (Toggle Plain Text)
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
The answer to the original questions is that _list needs to be declared as;
std::list<some_templated_class<some_object> > _list; Incidentally, it is not generally a good idea to have leading or trailing underscores on identifier names. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2007
Posts: 24
Rep Power: 0
![]() |
Actually I would like to store handlers in containers (boost.bind), but I thought it would be the best to store them in new templated object.
I'd like to be able to do: container.pushback(boost::bind(&Test::func,&test, someargument, argument2)); |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
You use boost.function of course.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Template Problem | pegasus001 | C++ | 13 | Jan 18th, 2007 6:30 AM |
| friends, templates, and other s**t | bl00dninja | C++ | 4 | Oct 14th, 2006 2:15 AM |
| dev c++ software, template problem | cairo | C++ | 11 | Jun 2nd, 2006 1:42 PM |
| Template + operator problem | Polyphemus_ | C++ | 3 | Sep 30th, 2005 7:43 PM |