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

  • Home
  • SEARCH
  • 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 8943941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:54:43+00:00 2026-06-15T11:54:43+00:00

I have defined a class template <class T> class NodeMap { NodeMap(int n, T

  • 0

I have defined a class

template <class T> class NodeMap {

NodeMap(int n, T defaultEntry = NULL);

virtual ~NodeMap();

T& operator[](const node& u);

...

}

which maps an object of type node to an object of parameter type T.

Now I’d like to have a class Matching, which is essentially a NodeMap<node>. For convenience, I’d like to add methods like isProperMatching(Graph& G) and match(node u, node v). Can Matching inherit from NodeMap<node>? Is it possible (and if yes, is it a good idea) to extend a template class with a fixed template parameter?

  • 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-15T11:54:44+00:00Added an answer on June 15, 2026 at 11:54 am

    You have the following possibilities as far at the code you’ve shown tells me what you are doing:

    1. Specialize Nodemap for T=node, to include the additional methods you want to have. For convenience you can then typedef Nodemap<node> to Matching. However this might add some code duplication of the Methods you have in the nonspecialized template.
    2. Derive from Nodemap<node> as you suggested. This is a valid approach, if you design Nodemap in a way that makes it a proper base class. The virtual destructor suggests you did that already, although it might not be necessary to make methods virtual at all.
    3. If possible, provide the additional functionality as free functions, so there is no need to derive from or specialize Nodemap<node>

    I would consider a mixed approach of the first two: Make a base class template (I’ll call it NodeMapBase) that contains the common functionality of NodeMaps and Matching, then derive the NodeMap template from the corresponding base class template (probably without adding much functionality) and derive Matching from NodeMapBase<node>. If you have a look at MSVC’s standard library implementation you see that a lot there.

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

Sidebar

Related Questions

Suppose you have: template<class T> class A { template<class T1> void foo(const T1& t1)
I have defined a generic tree-node class like this: template<class DataType> class GenericNode {
I have a class template where some methods are defined as virtual to give
I have a class template<typename T> class RGBHistogramTrait { public: RGBHistogramTrait(const QImage &image, RGBHistogram<T>
I have a template class btree and have defined a struct Node in the
I have a class for which I have defined comparison operator. Following is the
I have defined class template named CallBackAtInit which only purpose is to call a
I have a template class defined like so: template <class T> class Command {
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have a class defined as: class Obj { public: int width, height; Obj(int

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.