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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:42:34+00:00 2026-05-13T09:42:34+00:00

I have the following templated class, declared in an .hpp file with the implementation

  • 0

I have the following templated class, declared in an .hpp file with the implementation in a .inl file included at the end of the .hpp file.
It has a templated copy constructor, but I don’t know nor can’t find anywhere the correct syntax for implementing the templated copy constructor in the .inl file. Does anyone know the correct syntax for this?

Contents of Foo.hpp

template <class X>
class Foo
{
public:
    explicit Foo(Bar* bar);    

    //I would like to move the definition of this copy ctor to the .inl file
    template <class Y> explicit Foo(Foo<Y> const& other) :
       mBar(other.mBar)
    {
      assert(dynamic_cast<X>(mBar->someObject()) != NULL);
      //some more code
    }

    void someFunction() const;

private:
    Bar* mBar;
}
#include Foo.inl

Contents of Foo.inl

template <class X>
Foo<X>::Foo(Bar* bar) : 
   mBar(bar)
{
   //some code
}

template <class X>
Foo<X>::someFunction()
{
    //do stuff
}
  • 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-13T09:42:35+00:00Added an answer on May 13, 2026 at 9:42 am

    For the constructor you have two nested templates and you have to specify both when you define it in the .inl file:

    template <class X>
    template <class Y>
    Foo<X>::Foo(Foo<Y> const& other) : mBar(other.mBar) {
       assert(dynamic_cast<X>(mBar->someObject()) != NULL);
       //some more code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem using template instantiation [*]. file foo.h class Foo {
I have the following code. template<class key,class val> bool has_key(key chkey,std::map<key,val> map){ for (std::map<key,val>::iterator
I have written the following code: #include <iostream> using namespace std; template <class T>
I have got the following code #include <iostream> #include <string> template <typename T> class
I have the following template <h2>one</h2> <xsl:apply-templates select=one/> <h2>two</h2> <xsl:apply-templates select=two/> <h2>three</h2> <xsl:apply-templates select=three/>
I have the following xsl template that I'm using to group my xsl. The
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have the following simple button with an image as the template. The problem
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

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.