Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: template de...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 9583 of 9807
Post > Topic >>

Re: template depth problem

by David Pol <david@[EMAIL PROTECTED] > May 9, 2008 at 09:24 AM

On 9 mayo, 05:30, Venkat <swara...@[EMAIL PROTECTED]
> wrote:
> Trying to have the following usage; however, gcc is not liking.
>
> #include <boost/smart_ptr.hpp>
>
> namespace xyz {
> class elem {
> public:
>      typedef boost::shared_ptr<elem>     elem_sptr;
>
> };
> }
>
> #include <map>
>
> namespace abc {
> template <typename ObjectType>
> class BaseContainer
> {
>     typedef std::map<int, ObjectType::elem_sptr> Container;
>
>     // tried this too
>     //typedef std::map<int, boost::shared_ptr<ObjectType> > Container;
>
>     typedef Container::iterator iterator;
>
>      Container  c;
>
> };
> }
>
> void main()
> {
>     abc::BaseContainer<xyz::elem>  elem_container;
>
> }
>
> Any thoughts on the usage?

Hello,

Both ObjectType::elem_sptr and Container::iterator are qualified names
that depend on a template parameter, so you need to explicitly tell
the compiler to treat those names as types by using the typename
prefix (even if it does not make sense that they refer to a non-type).
Otherwise, those names are assumed to refer to non-types (even if that
leads to a syntax error).

// ...
template <typename ObjectType>
class BaseContainer
{
     typedef std::map<int, typename ObjectType::elem_sptr> Container;

     typedef typename Container::iterator iterator;

     Container  c;
};
// ...

Also, note that your definition of main() is non-standard. main() must
have a return type of type int ([basic.start.main]/2).

Regards,
David

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 5 Posts in Topic:
template depth problem
Venkat <swara101@[EMAI  2008-05-08 21:30:31 
Re: template depth problem
Dan Barbus <dan.barbus  2008-05-09 09:28:36 
Re: template depth problem
David Pol <david@[EMAI  2008-05-09 09:24:25 
Re: template depth problem
ciesizdz@[EMAIL PROTECTED  2008-05-09 09:24:12 
Re: template depth problem
Francis Glassborow <fr  2008-05-09 09:23:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 20:01:51 CDT 2008.