Computer Science Canada g++ compilation error |
Author: | deltatux [ Mon Feb 23, 2009 3:44 pm ] | ||
Post subject: | g++ compilation error | ||
Hey guys, I'm quite confused here. My program works perfectly when compiled on Visual Studio 2008 but it doesn't compile on G++. I don't even understand the error. I know that the ifstream is part of the C++ standard library so it makes even less sense: Quote: isbnprefix.cpp: In function 'int registered(FILE*, int)': isbnprefix.cpp:32: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)' /usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&) isbnprefix.cpp: In function 'int minNoDigits(FILE*, int)': isbnprefix.cpp:42: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)' /usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&) isbnprefix.cpp: In function 'int registered(FILE*, int, int)': isbnprefix.cpp:65: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)' /usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&) My isbnprefix.cpp as follows:
Thanks, deltatux |
Author: | DemonWasp [ Mon Feb 23, 2009 4:01 pm ] | ||
Post subject: | RE:g++ compilation error | ||
The error message is telling you that it can't find any function that can fulfill your call:
This is because that's not a valid constructor. See documentation on ifstream here: http://www.cplusplus.com/reference/iostream/ifstream/ , specifically its constructor (see http://www.cplusplus.com/reference/iostream/ifstream/ifstream.html ). You're really mixing C and C++ here. FILE is C, ifstream is C++. Visual Studio's implementation may be non-standard, which is why you had the other constructor there in VS. |
Author: | saltpro15 [ Mon Feb 23, 2009 4:48 pm ] |
Post subject: | RE:g++ compilation error |
... I was going to say you need the #include <fstream> but demonwasp's answer makes a lot more sense |
Author: | wtd [ Mon Feb 23, 2009 8:20 pm ] |
Post subject: | RE:g++ compilation error |
You are not going to make any substantial headway until you ditch the C/C++ bastardization. |