How many times will a class A constructor be called?
#include <string>

class A
{
public :
        A(const std::string & s) : m_name(s) {}
       ~A() { }
private :
        std::string m_name;
};

int main(int c, char * * v) 
{
        A r1(std::string(v[1]));
        const char * e = "Hello";
        A r2(std::string(e));
        std::string s(e);
        A r3(s);
        A r4(std::string("World"));
        return 0;
}
Explanation
A r1(std::string(v[1]))
and
A r2(std::string(е))
are functions declarations,
A (* ) (std::string *)
A (* ) (std::string)
are functions respectively.
C++ standard 8.2 Ambiguity resolution (8.2.1)

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты