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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:23:41+00:00 2026-05-18T22:23:41+00:00

Initially I was trying to typedef a template class and I got to the

  • 0

Initially I was trying to typedef a template class and I got to the “gotw 79” article.
And I didn’t want to create another class so I ended up doing the following. Basically typedef’ing inside the same class. It works obviously. but is it a good practice?

template <typename T,typename L>
class MyClass{
     typedef std::tr1::shared_ptr<MyClass<T,L> > shrdPtr;
}

Thank you.

  • 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-18T22:23:42+00:00Added an answer on May 18, 2026 at 10:23 pm

    Well, I’m not a big fan of it unless you are designing MyClass to be specifically used only within shared_ptr objects, at which point I would insist that requirement be enforced.

    It’s a little ridiculous to put typedefs for every unrelated template instantiation that you might use with a given object. Just because you might put MyClass in a shared_ptr is not a good reason to typedef it there. You going to put typedefs for std::vector, map, list, unordered_map, set, deque,….etc, etc, etc?

    But if MyClass extends shared_from_this and has private/protected constructors so that it can ONLY be created and immediately assigned to a shared_ptr then…sure…it’s part of the interface.

    If you’re trying to avoid having to type out long parameter lists to instantiate a shared_ptr for a templated type with lots of parameters then a better bet is an EXTERNAL utility object just like shown in the article you cited:

    template < typename T >
    struct instantiate_shared_ptr { typedef shared_ptr<T> type; };
    
    template < typename after typename > struct my_complex_template {};
    typedef my_complex_template<some parameters> mct_1;
    typedef instantiate_shared_ptr<mct_1>::type mct_1_sp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make the open_id_authentication plugin working. Initially was doing it with
I'm trying to create horizontal scroll view(s). Each view containing one image. [done] Initially
I'm trying to create an iOS application which upon loading, will initially connect via
I am trying to get the following working. It seemed to work initially, but
I am trying to create a Javascript application which displays initially Countries information, Selecting
a couple of queries with jquery... I'm trying to create a tabbed panel, initially
While trying to compile the code below: template <class T> struct scalar_log_minimum { public:
i am trying to install FOSRest & FOSRestBundle initially , i have specified following
I'm trying to implement (as a prototype initially), a richtextbox control which can be
I'm beginning python and I'm trying to use a two-dimensional list, that I initially

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.