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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:29:48+00:00 2026-06-05T17:29:48+00:00

Does a templated constructor (such as the following) override the implicit copy constructor? template

  • 0

Does a templated constructor (such as the following) override the implicit copy constructor?

template <class T>
struct Foo
{
    T data;

    // ...

    template <class U>
    Foo(const Foo<U> &other) : data((T)doSomethingWith(other.data)) {}

    // ...
};

If so, does it still override it if other is passed by value rather than constant reference?

If so, is there any way around this without explicitly defining a copy constructor?

  • 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-05T17:29:51+00:00Added an answer on June 5, 2026 at 5:29 pm

    No, that is not a copy constructor. Section 12.8 ([class.copy]) of the Standard requires that:

    A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments.

    The compiler will still implicitly generate a defaulted one.

    You can make that explicit (requires C++11) by

    Foo(const Foo<T>&) = default;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following are 2 of weak_ptr's constructors: http://msdn.microsoft.com/en-us/library/bb982126.aspx weak_ptr(const weak_ptr&); template<class Other> weak_ptr(const weak_ptr<Other>&);
Why does the following code give me an error (g++ 4.1.2)? template<class A> class
Why does the following give no compilation error?: // T.h template<class T> class X
Why this code does not compile (Cygwin)? #include <vector> template <class Ttile> class Tilemap
I have to implement template specialization, in implementing the constructor for specialized template class
I have the following templated class, declared in an .hpp file with the implementation
My code does not compile. Below is my code template <typename T> class TemplateClass
The default copy constructor that is synthesized by the compiler for a class that
I have a template based class [Allotter.h & Allotter.cpp]: template <typename allotType> class Allotter
I want a templated class with a templated conversion operator and a default constructor,

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.