I'm trying to clean up some code with ternary operators and I'm running into some compiler errors i can't make sense of.
The code I had before looks like this and runs fine.
if(!inFile.good())
throw -2;
getline(inFile, inLine);
And I'm trying to clean it up using this code instead.
(inFile.good()) ? getline(inFile, inLine) : throw -2;
But I'm getting the following errors.
g++ -w -o test orange_test.cpp
In file included from orange_test.cpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:39:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/streambuf:558:31: error: base class 'std::__1::ios_base' has private
copy constructor
_LIBCPP_EXTERN_TEMPLATE(class basic_ios<char>)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__config:462:54: note: expanded from macro '_LIBCPP_EXTERN_TEMPLATE'
#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:305:5: note: declared private here
ios_base(const ios_base&); // = delete;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:1706:31: note: implicit default copy constructor for
'std::__1::basic_ios<char>' first required here
_LIBCPP_EXTERN_TEMPLATE(class basic_istream<char>)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__config:462:54: note: expanded from macro '_LIBCPP_EXTERN_TEMPLATE'
#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
^
./orange_model.hpp:145:23: note: implicit default copy constructor for 'std::__1::basic_istream<char>' first required here
(inFile.good()) ? getline(inFile, inLine) : throw -2;
^
1 error generated.
make: *** [main] Error 1
I can't make any sense of it. Is there some limitation of ternary operators or scope that I'm not aware of? Any help or insight would be greatly appreciated. Thanks in advance, Max
Edit
From looking at it the main error seems to be
error: base class 'std::__1::ios_base' has private copy constructor
It's complaining about the std::getline(inFile, inLine) function.
Answer
This code gets it running smoothly. Thanks everyone!
inFile.good() ? (void) getline(inFile, inLine) : throw -2;