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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:58:33+00:00 2026-06-14T02:58:33+00:00

I am implementing polymorphic protocol handlers and in my base class I want to

  • 0

I am implementing polymorphic protocol handlers and in my base class I want to have a pure virtual function where the template function parameter is unspecified. But my compiler is complaining. I guess this cannot be done. Anyone any suggestions on how to achieve this? If at all possible? Otherwise I will have to scrap the polymorphic idea.

Here is my code which gives me error C2976 ‘ProtoWrapper’ : too few template arguments. compiler=MSVC++2008.

#include "smartptrs.hpp"
#include <iostream>

class realproto {
public:
   const char* getName() const { return "realproto"; }
}; 

class real2ndproto {
public:
   const char* get2Name() const { return "real2ndproto"; }
}; 


template<typename T>
class ProtoWrapper : public ref_type {
public:
   ProtoWrapper(T* real) : m_msg(real) {}
   ~ProtoWrapper() { delete m_msg; }  //cannot have smart ptr on real_proto - so do this way

   T* getMsg() { return m_msg; }

private:
   T* m_msg;
};


class ProtocolDecoder 
{
public:
  virtual void Parse(ProtoWrapper<>* decoded_msg) = 0;  //problem line - compile error
};

class CSTA2Decoder  : public ProtocolDecoder
{
public:
   virtual void Parse(ProtoWrapper<realproto>* decoded_msg) {
      realproto* pr = decoded_msg->getMsg();
      std::cout << pr->getName() << std::endl;
   }
};


int main(int argc, char* argv[])
{
   {
      ref_ptr<ProtoWrapper <realproto> > msg2 = new ProtoWrapper<realproto>(new realproto);

      realproto* pr1 = msg2->getMsg();

      std::cout << "created new realproto\n";
   } 

    return 0;
}
  • 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-14T02:58:34+00:00Added an answer on June 14, 2026 at 2:58 am

    To pull this off, you need to turn ProtocolDecoder into a class template:

    template <typename T>
    class ProtocolDecoder 
    {
    public:
      virtual void Parse(ProtoWrapper<T>* decoded_msg) = 0;  //problem line - compile error
    };
    
    class CSTA2Decoder  : public ProtocolDecoder<realproto>
    {
      //...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When implementing polymorphic behavior in C++ one can either use a pure virtual method
I want to use unity for a polymorphic event aggregation/handling where handlers are registered
Implementing swing applications, often you realize class of components that should have a coherent
Implementing a condition in template match <xsl:template match="a[!(img)and(not(@id))]"> I want to write a template
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
when implementing a recursive function during development, i will use a counter and exit
When implementing a hash table using a good hash function (one where the probability
When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have
I want to have one model & view that is served by multiple controllers
Implementing a Thread by providing a new class that extends Thread and overriding its

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.