Strange VC++ compile error, C2244

后端 未结 3 1634
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 01:50

Take a look at this peice of code:

template 
Pointer::Iterator> BinaryTree::GetBegi         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 02:03

    For those interested, I tried writing a minimal sample reproducing the problem:

    template 
    struct Pointer {};
    
    template 
    struct Collection {
        struct Iterator {};
    };
    
    template 
    struct BinaryTree : Collection{
        Pointer::Iterator> GetBeginning() const;
    
        struct BinaryTreeIterator : Collection::Iterator {
            template 
            BinaryTreeIterator(BinaryTreeIterator*, X) {}
            struct Position {
                static int atBeginning() { return 0; }
            };
        };
    };
    
    template 
    Pointer::Iterator> BinaryTree::GetBeginning() const
    {
        return Pointer::Iterator>();
    }
    
    int main(){
        BinaryTree bt;
        bt.GetBeginning();
    }
    

    And yes, I get the error too. I can't see any obvious errors in what we've seen of your code, but then again, just this example has used more nested classes and inheritance than most sane C++ programmers do in a year, so I can't say for sure that your code is or isn't correct.

    Moreover, I've had to guess quite a bit to piece this together. (What's atBeginning supposed to be? What are the actual class interfaces?)

    But I suspect it'd work better (and be more readable and easier to debug) if you didn't inherit everything from everything else.

    Update I tried compiling the above with GCC and Comeau's online compiler, and both accepted it. So it seems like it could be a compiler bug.

提交回复
热议问题