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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:48:01+00:00 2026-05-11T18:48:01+00:00

I have a class that I’ve been provided that I really don’t want to

  • 0

I have a class that I’ve been provided that I really don’t want to change, but I do want to extend. I’m a pattern and template newbie experimenting with a Decorator pattern applied to a template class. Template class contains a pointer-to-member (if I understand the semantics correctly) in yet another class. The pointer-to-member is the deserializer of an XML istream. The type ‘T’ is the type of XML document to be deserialized.

template <typename T> class B {
public:
  typedef std::auto_ptr<T> MYFUN( 
    std::istream&, const std::string&, const std::string& );

public:
  B<T>( MYFUN* p );

private:
  MYFUN *fptr;
  std::string aString1;
  std::string aString2;

};

The typedef looks odd to me after reading http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.5, and yet this class seems to work fine as-is. There aren’t any additional #defines in the provided header file, so this is a little mysterious to me.

Now I try to extend it, as Decorator because I want to do a bit more work on the auto_ptr object returned by MYFUN:

template <typename T>
class D : public class B<T>
{
  D( B<T>::MYFUN *fPtr, B<T> *providedBase ); //compiler complaint
  //Looks like B
  private:
    B* base_;

};

template <typename T>
D<T>::D( B<T>::MYFUN *p, B<T> *base ) //compiler complaint
:
B<T>::B( p ), base_(providedBase)
{ }

When trying to compile this, I get a syntax complaint at the two lines shown. Error is something like “expected ‘)’ at *”. There is no complaint about MYFUN being undefined.

When I re-define the pointer-to-member in D with the same signature as in D, i.e.

//change MYFUN to NEWFUN in D)
typedef std::auto_ptr<T> MYNEWFUN( 
    std::istream&, const std::string&, const std::string& );

This works. I prefer not to have to do this for every D/Decorator I might make of B. I tried to perform the typedef more globally, but couldn’t get the syntax right due to the template parameter being undefined.

  • 1 1 Answer
  • 1 View
  • 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-11T18:48:01+00:00Added an answer on May 11, 2026 at 6:48 pm

    The compile error is due to the fact that the compiler can’t tell you are talking about a type.

    Try:

    D( typename B<T>::MYFUN *fPtr, B<T> *providedBase );
    

    and

    template <typename T>
    D<T>::D( typename B<T>::MYFUN *p, B<T> *base )
    

    See: the templates section of the C++ FAQ Lite for more details on why this is necessary, but the summary is that because of the possibility of template specialization, there is no way for the compiler to be sure that B<T>::MYFUN is actually referring to a type.

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

Sidebar

Related Questions

I have a class that I want to use to store properties for another
I have a class that map objects to objects, but unlike dictionary it maps
I want to have class that can be instantiated with list, array, seq, set,
I have a French site that I want to parse, but am running into
I have class X that implements Queue. I want to pass Class X's Object
I have class that extends another class, that extend another class.. and so on.
I have class myCollection that inherit from Dictionary. Want to hide the add method
I have class (MyCustomWebView) that extend webview can i do something like this ?
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate

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.