Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
Consider supporting C++ Insights
×
Sponsors:
Made by
Andreas Fertig
Source:
#include <iostream> template<typename T> class Container { public: Container() : data() { } Container(const Container &c) : data(c.data) { std::cout << "COPY CONSTRUCTOR" << std::endl; } // This is what I call a "templated copy constructor". // If I remove this, the operator=() does not compile with a different type template<class U> Container(const Container<U> &c) : data(c.getData()) { std::cout << "TEMPLATE COPY CONSTRUCTOR??" << std::endl; } Container &operator=(const Container &c) { std::cout << "assignment operator" << std::endl; if (this == &c) return *this; this->data = c.getData(); return *this; } const T &getData() const { return this->data; } private: T data; }; int main() { Container<int> c1; Container<float> c2; c2 = c1; // Assigning a Container<int> to a Container<float> return 0; }
Insight:
Console: