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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:49:40+00:00 2026-06-10T12:49:40+00:00

Im having a problem with a typedef below, I can seem to get it

  • 0

Im having a problem with a typedef below, I can seem to get it right:

template <typename T>
  struct myclass1 {
  static const int member1 = T::GetSomeInt();
};

template <int I>
struct myclass2 {
  typedef myclass1< myclass2<I> > anotherclass;
  static int GetSomeInt();
};

anotherclass MyObj1; // ERROR here not instantiating the class

When I try and initialize a anotherclass object, it gives me an error.

Any idea what I am doing wrong? There seems to be a problem with my typedef.

Any help is appreciated,
Thanks
Bryan

  • 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-06-10T12:49:42+00:00Added an answer on June 10, 2026 at 12:49 pm

    You’re referring to anotherclass directly. That name doesn’t exist at that scope. You need to declare your variable as

    myclass2<some_int>::anotherclass MyObj1;
    

    where some_int is whatever integer value you want to parameterize myclass2 with.

    I think you’ll also need to mark myclass2<I>::GetSomeInt() as being constexpr so it can be used in the initializer of myclass1<T>::member1.

    With those tweaks, the following code compiles just fine:

    #include <iostream>
    
    template<typename T>
    struct myclass1 {
        static const int member1 = T::GetSomeInt();
    };
    
    template<int I>
    struct myclass2 {
        typedef myclass1<myclass2<I>> anotherclass;
        constexpr static int GetSomeInt() { return I; };
    };
    
    int main(int argc, char *argv[]) {
        myclass2<3>::anotherclass obj;
        std::cout << obj.member1 << std::endl;
    }
    

    Note, this requires C++11 for constexpr. If you want C++03 then I don’t think your myclass1<T>::member1 is legal.

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

Sidebar

Related Questions

Having a problem with print strings from structs in C... typedef struct box{ char
I am having problem to get a numerical value for this expression where I
I'am having problem in accessing json array elements. Below is the response when i
Recently I am having many problem with typedef and incomplete type when I changed
I am having trouble freeing a pointer in a pointer array (values). typedef struct
I'm having problems with const char array being stored to a struct, then when
I'm having a small problem trying to malloc this struct. Here is the code
I am having a problem with trying to typedef myself a nice handy tstring
I'm having a problem figuring out how to initiate an array of struct pointers.
Problem : Trying to sort an array coming from a typedef struct I created

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.