Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 117749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:23:08+00:00 2026-05-11T03:23:08+00:00

I have a template class where I want to use objects of that class

  • 0

I have a template class where I want to use objects of that class (along with the parameterized type) inside a map. So far this is the solution that I’ve been able to arrive at:

class IStatMsg;  template <typename T> class ITier { public:      // Methods     ITier(TierType oType) : o_Type(oType){};     virtual ~ITier(){};      typename ITier<T> ParamITier;  // line 60      ITier* Get(T oKey)     {         std::map<T, ParamITier*>::iterator it = map_Tiers.find(oKey);   // line 64          if (it != map_Tiers.end())             return it->second;          return NULL;     }      void Set(T oKey, ITier* pTier)     {         map_Tiers.insert(pair<T, ParamITier*>(oKey, pTier)); // line 74     }      TierType GetType() { return o_Type; }  protected:     // Methods      // Attributes     std::map<T, ParamITier*> map_Tiers;  // line 83     TierType o_Type;  private:     // Methods      // Attributes }; 

But when I try to compile this code I get a long list of errors:

/home/gayanm/street/src/QueryServer_NEW/ITier.h:60: error: expected nested-name-specifier /home/gayanm/street/src/QueryServer_NEW/ITier.h:60: error: ITier<T>' specified as declarator-id /home/gayanm/street/src/QueryServer_NEW/ITier.h:60: error: perhaps you wantITier’ for a constructor /home/gayanm/street/src/QueryServer_NEW/ITier.h:60: error: two or more data types in declaration of ITier<T>' /home/gayanm/street/src/QueryServer_NEW/ITier.h:60: error: expected;’ before ‘ParamITier’ /home/gayanm/street/src/QueryServer_NEW/ITier.h:83: error: ParamITier' was not declared in this scope /home/gayanm/street/src/QueryServer_NEW/ITier.h:83: error: template argument 2 is invalid /home/gayanm/street/src/QueryServer_NEW/ITier.h:83: error: template argument 4 is invalid /home/gayanm/street/src/QueryServer_NEW/ITier.h:83: error: ISO C++ forbids declaration of map_Tiers’ with no type /home/gayanm/street/src/QueryServer_NEW/ITier.h: In member function ITier<T>* ITier<T>::Get(T)': /home/gayanm/street/src/QueryServer_NEW/ITier.h:64: error:ParamITier’ undeclared (first use this function) /home/gayanm/street/src/QueryServer_NEW/ITier.h:64: error: (Each undeclared identifier is reported only once for each function it appears in.) /home/gayanm/street/src/QueryServer_NEW/ITier.h:64: error: template argument 2 is invalid /home/gayanm/street/src/QueryServer_NEW/ITier.h:64: error: template argument 4 is invalid /home/gayanm/street/src/QueryServer_NEW/ITier.h:64: error: expected ;' before '::' token /home/gayanm/street/src/QueryServer_NEW/ITier.h:66: error:it’ undeclared (first use this function) /home/gayanm/street/src/QueryServer_NEW/ITier.h:66: error: request for member end' in ((ITier)this)->ITier::map_Tiers’, which is of non-class type int' /home/gayanm/street/src/QueryServer_NEW/ITier.h: In member functionvoid ITier::Set(T, ITier)’: /home/gayanm/street/src/QueryServer_NEW/ITier.h:74: error: request for member insert' in ((ITier*)this)->ITier::map_Tiers’, which is of non-class type int' /home/gayanm/street/src/QueryServer_NEW/ITier.h:74: error:pair’ undeclared (first use this function) /home/gayanm/street/src/QueryServer_NEW/ITier.h:74: error: expected primary-expression before ‘,’ token /home/gayanm/street/src/QueryServer_NEW/ITier.h:74: error: ParamITier' undeclared (first use this function) /home/gayanm/street/src/QueryServer_NEW/ITier.h:74: error: expected primary-expression before '>' token /home/gayanm/street/src/QueryServer_NEW/ITier.h: At global scope: /home/gayanm/street/src/QueryServer_NEW/ITier.h:93: error: baseITier’ with only non-default constructor in class without a constructor /home/gayanm/street/src/QueryServer_NEW/ITier.h:109: error: expected class-name before ‘{‘ token

Could you please point out how to fix these?

Thank You.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:23:09+00:00Added an answer on May 11, 2026 at 3:23 am

    Line 60 does not access a depending name. What you use is ITier<T> of which the compiler knows it’s a template given an argument. Instead of typename you want to use typedef 😉

    Line 64 does access the depending name iterator which is a type-name, so you have to put typename before std::map. I put the two disambiguations, template and typename on this answer: Disambiguations of dependent names.

    Line 74 would be right, if you fix the bug in Line 60, as far as i can see.

    Line 83 is alright in itself as far as i can see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a template class that looks something like what I have
I have this problem with Slim framework . I have class Template that have
I have custom binary tree class that holds values of template type T (it
I have an abstract Handle<T> class that contains references an objects of type T.
I have my templated container class that looks like this: template< class KeyType, class
I have a templated class that I want to avoid copying (because of the
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
I have non-template class with a templatized constructor. This code compiles for me. But
I have the template class and array of pointers to objects and overloaded logic
I have a template class with a variadic template member function that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.