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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:45:21+00:00 2026-06-17T22:45:21+00:00

I have this class: template <typename T, uint64_t N> struct Probe { static const

  • 0

I have this class:

template <typename T, uint64_t N>
struct Probe {
  static const uint64_t Counter = N;
  typedef T Type;
};

Which I utilize as:

typedef Probe <int, 0> FirstIntProbe;
typedef Probe <int, 1> SecondIntProbe;
typedef Probe <float, 2> FloatProbe;

Is it possible to create a compile time\macro method which allows me to instantiate this class without specifying the second parameter such as:

typedef Probe <int, Something?> FirstIntProbe;
typedef Probe <int, Something?> SecondIntProbe;
typedef Probe <float, Something?> FloatProbe;

I assume this is isn’t possible, but then again I’ve seen people do things in C++ I wouldn’t think was possible before.


Update:

  • It is not necessary to increase by one, it’s just important that
    every probe have it’s own number.
  • It is not needed to have unique
    number across different .cpp files\translation units.
  • 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-17T22:45:23+00:00Added an answer on June 17, 2026 at 10:45 pm

    You can look into using the __COUNTER__ macro, which is a compiler extension (but supported on GCC and MSVC, among others). Note that __COUNTER__ is unique only per-translation-unit, i.e. per .cpp file.

    edit: Header inclusion in multiple translation units is OK. This example links and runs perfectly fine (built on GCC 4.5):

    probe.h:

    template <typename T, int N>
    struct Probe {
        typedef T Type;
    };
    
    #define DECLARE_PROBE(type) typedef struct Probe<type, __COUNTER__>
    

    main.cpp:

    #include "test.h"
    
    DECLARE_PROBE(int) intprobe;
    DECLARE_PROBE(float) floatprobe;
    
    int main(int argc, char** argv) {
        intprobe ip;
        floatprobe fp;
        return 0;
    }
    

    test.cpp:

    #include "test.h"
    
    DECLARE_PROBE(int) intprobe;
    DECLARE_PROBE(float) floatprobe;
    
    static intprobe ip;
    static floatprobe fp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snippet of code: template<typename... Args> class function_helper<void(Args...)>{ public: typedef void(*generic_function)(Args...); static
I have this code: class USerializer { public: template<typename T> static std::string serialize(std::list<T*> listOfObjectToSerialize)
Say I have this: template<typename T, int X> class foo { public: void set(const
I have a class template <typename T> struct Trait { typedef std::false_type IsGood; };
I have this code: struct A{}; template<class T = A> struct B { void
Suppose I have a function which looks like this: template <class In, class In2>
I got class with template methods that looks at this: struct undefined {}; template<typename
I have this code namespace MSL{ template <typename T> class TListNode; template <typename T>
I have this class for double linked lists: template <typename T> class Akeraios {
Let's say I have this : class A { virtual int Method2(){/*...*/} }; template<typename

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.