Witam, przerabiam różne przykłady z C++ i natrafiłem na jeden który mnie zaciekawił. Chciałbym się was zapytać jakim cudem mogę wywołać f(3)? Rozumiem jakbym to zrobił
w taki sposób f(A(3)), ale dlaczego skoro funkcja oczekuje obiektu klasy const A &a1, a dostaje int, to nie protestuje tylko uruchamia konstruktor z parametrem int klasy A ?
#include<iostream>
using namespace std;
class A
{
public:
A(int n = 0) : m_n(n)
{
std::cout << 'd';
}
A(const A& a)
: m_n(a.m_n)
{
std::cout << 'c';
}
private:
int m_n;
};
void f(const A &a1, const A &a2 = A())
{
cout << "f";
}
int main()
{
f(3);
getchar();
return 0;
}