Hi there,
I have a File class and I want to call its constructor. It has three constructors, they look like this:
Code:
File(int fd = -1); // Construct from file descriptor...
File(const std::string &name, Mode); // ...from file name + open mode...
File(const File &file); // ...or from other descriptor.
In a simple program (that at the moment just opens a file to see if it is there) I accidentally called it with
just a string argument - i.e.:
Code:
// Using just "File file(argv[1])" seemed to want to use the
// constructor that takes an int.
File file(std::string(argv[1]));
I got no compile-time error, and the output of nm shows no symbol relating to the File class is used (i.e. the output of "nm program|grep File"). When the program was run, no exception was thrown if the file didn't exist, as I would have expected.
When I change the call to:
Code:
File file(std::string(argv[1]), File::RdOnly);
I get both (i) the symbols for the appropriate constructor and destructor in the output file and (ii) the correct behaviour (i.e. an exception being thrown) if the file doesn't exist.
Can anybody tell me what's going on here?