• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

a question about C++ template.... (template of template)..

Question #1:
template <class G<typename T> >
class Container : public G<T>
{
        void add (const T &obj)
        {}
 
        void remove (const T &obj)
        {}
};

It seems above code is invalid...Why and how to fix it?

Question #2:
How to implement a thread-safe (i.e. using mutex) container by using STL library???

many thanks.

0
zollen
Asked:
zollen
  • 3
  • 2
1 Solution
 
burcarpatCommented:
(1) you need this:

    template <
      typename T,
      template <class> G
    >
    class Container : public G<T> {


(2) for thread-safety issues of STL, see,

  http://www.sgi.com/tech/stl/thread_safety.html
0
 
burcarpatCommented:
not to sound condescending but can i ask why you gave a C as the grade?  'cause, for your first question, i fixed the problem and that's the only fix in C++; not like i gave an inferior answer or something and for your second question, i pointed out the best available web resource there is.  that page is considered the ultimate authority on multi-threading issues and stl
0
 
zollenAuthor Commented:
You solution fail to compile. However, I feel that you are on the right track and it inspires me to pursue this problem a little further. Here is the correct solution:


template <typename T, template <class> class G>
class Container : public G<T>
{

};


Because of your info, my project can move one step forward.
You are still a great helper!

I hope you can overlook the grade..
Many Many thanks.
stephen
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
burcarpatCommented:
your record shows that you are not a newbie so you should have known better.  experts don’t test every single line of code they post;  especially when it's this simple.  for simple questions, i generally just type into the comment box on the ee web page and sometimes syntax errors find their way in.  anyway, here's a tip for future use:  when something like this happens, ask for clarification, don't just give a C.  a C is considered an insult around here
0
 
ExceterCommented:
>> a C is considered an insult around here

Depending on the situation so is a B. For example,

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20504367.html

Exceter
0
 
zollenAuthor Commented:
Hi,
 

   Thanks for your advice. You have done your best to help us. I shall be more considerate in the future.


regards,
stephen
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now