좋아, 나는 그것이 단지 불필요한 물건을 가지고 있고 문제의 코드가 죽은 코드 & hellip인데도 전체 프로그램을 게시 할 것이다.자격이 필요없는 이유는 무엇입니까?
#include <iostream>
#include <fstream>
namespace detail {
// Solution by Johannes Schaub alias litb
// http://groups.google.com/group/comp.std.c++/browse_thread/thread/b567617bfccabcad
template<int> struct D {};
typedef char yes[1];
typedef char no[2];
template< class T, class U >
yes& f(int, D< sizeof T(*(U*)0) >* = 0);
template< class T, class U >
no& f(...);
template< class To, class From >
struct IsExplicitlyConvertible
{
enum{ yes = (sizeof detail::f< To, From >(0) == sizeof(detail::yes)) };
};
bool const streamsSupportWindows =
IsExplicitlyConvertible< std::ofstream, wchar_t const* >::yes;
}
class InFStream
: public std::ifstream
{
public:
InFStream() {}
explicit InFStream(
char const* filename,
ios_base::openmode mode = ios_base::in | ios_base::out
)
: std::ifstream(filename, mode)
{}
};
int main()
{
using namespace std;
cout << (detail::streamsSupportWindows
? "Windows-enabled"
: "Ach, no Windows support"
) << endl;
}
MSVC 및 g ++에서 정상적으로 컴파일됩니다. 그러나 InFStream
클래스의 경우 ios_base
을 수혜 할 필요가없는 이유는 무엇입니까? 또는 동일한 질문을 정말로 자격을 ifstream
생성자 초기화 프로그램 목록에 사용해야합니까?
ifstream은 std 네임 스페이스에 있기 때문에? 왜 당신이 그것을 사용할 필요가 없다고 생각합니까? –
@VJo :'ios_base'도'std' 네임 스페이스에 있습니다. 내가 언급 한 컴파일러가이 코드를 잘 컴파일한다고 생각하는 이유는 그것이 그렇기 때문입니다. ㅎ. –
InFStream 클래스가 std :: ifstream에서 상속 받았기 때문에 std :: ios_base에서 상속받을 가능성이 있습니다. 따라서 모든 ios_base 열거 형은 상속을 통한 클래스의 멤버이므로 완전한 자격이 필요하지 않습니다. – Praetorian