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 6078373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:49:34+00:00 2026-05-23T10:49:34+00:00

In the following code, I get a compile error that I don’t have if

  • 0

In the following code, I get a compile error that I don’t have if I remove the templates :

template<int DIM> class myClass
{
public :
    enum Mode {aa,bb};
    myClass(){};
};

template<int DIM> class  myClass2
{
    myClass2(){};
    void myfunc(myClass::Mode m);
};

template<int DIM>
void myClass2<DIM>::myfunc(myClass<DIM>::Mode m)
{
}

test.cpp(19) : warning C4346: ‘myClass::Mode’ : dependent name is not a type
prefix with ‘typename’ to indicate a type
test.cpp(19) : error C2146: syntax error : missing ‘)’ before identifier ‘m’

If I remove the like:

template<int DIM>
void myClass2<DIM>::myfunc(myClass::Mode m)

I get :

test.cpp(19) : error C2955: ‘myClass’ : use of class template requires template argument list

And if I put the definition of myfunc directly in the declaration of the class (which I would like to avoid), it works.

What should I do and why does this happen?

Thanks

  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-05-23T10:49:35+00:00Added an answer on May 23, 2026 at 10:49 am

    I believe that you have two problems in your code. The first is in this declaration in myClass2:

    void myfunc(myClass::Mode m);
    

    Because myClass is a template, you need to specify what the template parameter is. I assume that you probably meant to write

    void myfunc(myClass<DIM>::Mode m);
    

    However, due to a weird idiosyncrasy in C++, you would write this as

    void myfunc(typename myClass<DIM>::Mode m);
    

    The typename keyword here tells C++ that Mode is the name of a type nested inside of the class myClass<DIM>.

    Similarly, later in the code, the code

    template<int DIM>
    void myClass2<DIM>::myfunc(myClass<DIM>::Mode m)
    {
    }
    

    should read

    template<int DIM>
    void myClass2<DIM>::myfunc(typename myClass<DIM>::Mode m)
    {
    }
    

    to tell the compiler that Mode is the name of a type.

    Hope this helps!

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

Sidebar

Related Questions

In the following code, I get a compile time error: ByRef Argument type mismatch.
In the following code, I get a compile time error because i is treated
For the attached code, I get the following compile time error : exception during
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
I get the following two error messages when I compile the below code for
Why does the following code get the runtime error: Members of the Triggers collection
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
I have the following code: import java.util.*; public class SellTransaction extends Transaction { private
I have the following code that calls the function uint32_pack. This program compiles with

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.