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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:50+00:00 2026-05-29T03:48:50+00:00

I want to generate many sub-class which only has little difference, so I want

  • 0

I want to generate many sub-class which only has little difference, so I want to use macro to simplify my job. The macro define below:

#define DECLARE_SUB_CLASS(sub_class_name, base_class_name, value1) \
class sub_class_name:base_class_name \
{ \
public: \
    virtual int initialize(const void *); \
    virtual int run(const void *); \
    virtual void reset(); \
    virtual int output(const char*); \
    virtual void terminate(); \
private: \
    static const char m_szValue=#value1; \
};

I use it like this:

DECLARE_SUB_CLASS(RTCount13, RTCountBase, 13);

when I compiling with VC2005, it say

error C2065: 'RTCount13' : undeclared identifier

what’s the problem?

  • 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-29T03:48:50+00:00Added an answer on May 29, 2026 at 3:48 am

    Use gcc -E (or similar for other preprocessor)

    gcc -E prepro.cxx

    # 1 "prepro.cxx"
    # 1 "<built-in>"
    # 1 "<command-line>"
    # 1 "prepro.cxx"
    # 17 "prepro.cxx"
    class RTCount13:RTCountBase { 
      public: 
      virtual int initialize(const void *); 
      virtual int run(const void *); 
      virtual void reset(); 
      virtual int output(const char*); 
      virtual void terminate(); 
      private: 
      static const char m_szValue="13"; 
    };;
    

    You try to assign "13" to a char.

    By the way you could also use a template instead of a macro to do the exact same thing your macro did (namely to declare but not define the methods). Here’s a complete (trimmed down) example with separate method definitions.

    #include <iostream>
    class RTCountBase {};
    
    template <class base_class_name, int v>
    class RTCount: base_class_name { 
      public: 
       virtual int output(); 
       virtual void terminate(); 
      private: 
       static const int m_szValue=v; 
    };
    
    template <class base_class_name, int v>
    int RTCount<base_class_name,v>::output(){ return m_szValue; }
    
    template <class base_class_name, int v>
    void RTCount<base_class_name,v>::terminate(){ std::cout <<" term "<<std::endl; }
    
    typedef RTCount<RTCountBase,13> RTCount13; // typedef instead of macro
    typedef RTCount<RTCountBase,14> RTCount14;
    
    int main(){
       RTCount13 myc13;
       RTCount14 myc14;
       std::cout << "my13: "<<myc13.output()<<std::endl;
       std::cout << "my14: "<<myc14.output()<<std::endl;
       return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class of 30 students and want generate every possible
I want to generate random colours which can be attractive in pie charts.I have
I have a Post model. Posts have many Comments. I want to generate a
I want to generate a Class (.as) file and store it on the users
I want to set up an internal foswiki to which only authorized users have
Situation: I have a C# program which does the following: Generate many files (replacing
Example class User has_many :tickets end I want to create association which contains logic
Given an undirected graph, I want to generate all subgraphs which are trees of
I want to generate a thumbnail preview of videos in Java. I'm mostly JMF
I want to generate some XML in a stored procedure based on data in

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.