?
Solved

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

Posted on 2003-02-21
6
Medium Priority
?
281 Views
Last Modified: 2010-04-01
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
Comment
Question by:zollen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
burcarpat earned 200 total points
ID: 7997634
(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
 
LVL 7

Expert Comment

by:burcarpat
ID: 7997873
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
 

Author Comment

by:zollen
ID: 7999921
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
Technology Partners: 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!

 
LVL 7

Expert Comment

by:burcarpat
ID: 8000069
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
 
LVL 8

Expert Comment

by:Exceter
ID: 8000383
>> 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
 

Author Comment

by:zollen
ID: 8000571
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question