Ich versuche, Vorlage Konstruktor mit einem Parameter zu verwenden. Ich versuche 2 Fälle const Parameter und nicht-const.Vorlage Konstruktor ein Parameter const und nicht const
class Foo1
{
public:
Foo1() {}
template <typename T>
Foo1(const T& f)
{
cout<<"Foo1"<<endl;
}
};
class Foo2
{
public:
Foo2() {}
template <typename T>
Foo2(T& f)
{
cout<<"Foo2"<<endl;
}
};
int main()
{
Foo1 f1;
Foo1 f11(f1);
Foo2 f2;
Foo2 f21(f2);
}
Die Ausgabe lautet: foo2
so Standard Copykonstruktor für Foo1 erzeugt wird und nicht für foo2.
wenn ich Hauptfunktion zu ändern:
int main()
{
const Foo1 f1;
Foo1 f11(f1);
const Foo2 f2;
Foo2 f21(f2);
}
Ausgang ist leer:
so Kopie beide geerated aufgebaut. Warum ist das Verhalten?