How to compare two std :: istream links?

I switch from compilers from GCC to Clang / LLVM and run compilation errors that I have not experienced before.

I have a class that looks something like this:

#include <iostream>

class foo {
    public:
        bar(std::istream& is) : _fp(is), _sCheck(is != std::cin) { /* ... */ }
    private:
        std::istream& _fp;
        bool _sCheck;
}

When I compile this file, I get the following error with clang++where the initialization of the private variable ends _sCheck:

error: invalid operands to binary expression ('std::istream' (aka 
'basic_istream<char>') and 'istream' (aka 'basic_istream<char>'))

  (is != std::cin)
   ~~ ^  ~~~~~~~~

If both objects in this address mapping are of the same type, why does it clang++return an error, but g++not?

I tried dynamic_castto make them like std::istream&, but that also returned an error:

error: invalid operands to binary expression ('std::istream' (aka 
'basic_istream<char>') and 'std::istream')

(is != dynamic_cast<std::istream&>(std::cin))
 ~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I apologize in advance if this is a stupid question; I appreciate any pointers.

+2
source share
1

, , , . , GCC , std::istream, std::basic_istream. :

_sCheck(&is != &std::cin)
+7

Source: https://habr.com/ru/post/1616062/


All Articles