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! ]


|