G
Guest
Please, could someone explain me why there are errors in the following code?
#include <iostream>
#include <string>
using namespace std;
class Log
{
public:
explicit Log(const string& msg) { cout << msg << endl; }
};
int main()
{
string msg = "Hello, World!";
Log(msg.c_str()); // It Works.
Log(msg); // Errors C2371 and C2512!
return 0;
}
I'm using VC++ .NET 2003.
Thanks in advance.
#include <iostream>
#include <string>
using namespace std;
class Log
{
public:
explicit Log(const string& msg) { cout << msg << endl; }
};
int main()
{
string msg = "Hello, World!";
Log(msg.c_str()); // It Works.
Log(msg); // Errors C2371 and C2512!
return 0;
}
I'm using VC++ .NET 2003.
Thanks in advance.