Ghita
Ghita

Reputation: 4505

C++ templates: template argument error

I have

    template <typename ConcContainer>
    class WebBrowsingPolicyData
    {
    public:
        typedef ConcContainer<std::shared_ptr<WBRuleDetails>>::iterator iterator;
    ...
    private:
    ConcContainer<std::shared_ptr<WBRuleDetails>> usersData_;
    CRITICAL_SECTION critSection

I get a compile error at line (Error 6 error C2238: unexpected token(s) preceding ';')

typedef ConcContainer<std::shared_ptr<WBRuleDetails>>::iterator iterator

How can I make a typedef inside the template ? I must be missing something..

Upvotes: 1

Views: 154

Answers (2)

hmjd
hmjd

Reputation: 122011

ConContainer is itself a template so it needs to be a template template parameter:

template <template <typename T> class ConcContainer>
class WebBrowsingPolicyData
{
public:
    typedef typename ConcContainer<std::shared_ptr<WBRuleDetails>>::iterator iterator;
};

Upvotes: 3

John Dibling
John Dibling

Reputation: 101506

Two possibilities:

  1. The compiler is having trouble with >>. Insert a space. Note that if you're using a C++11-conformant compiler, this should not be an issue.

example:

typedef ConcContainer<std::shared_ptr<WBRuleDetails> >::iterator iterator;
  1. ConcContainer doesn't have a member or typedef iterator. Check to make sure that it really does.

EDIT: This is not the most vexing parse.

Upvotes: 0

Related Questions