Strange VC++ compile error, C2244

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

Take a look at this peice of code:

template 
Pointer::Iterator> BinaryTree::GetBegi         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-12 02:07

    It will compile if you change it to this:

    template 
    struct BinaryTree : Collection {
        Pointer::Iterator> GetBeginning() const;
    
    };
    
    template 
    Pointer::Iterator> BinaryTree::GetBeginning() const
    {
        return Pointer::Iterator>();
    }
    

    In general, the original code isn't quite right because it implies that GetBeginning() can return any collection, while (I'm assuming) it can only return binary tree collections.

    EDIT:

    After some digging, it seems that VC++ doesn't handle well injected class names. That is, the original code will compile if you remove from Collection::Iterator in the method declaration:

    template 
    struct BinaryTree : Collection {
        Pointer GetBeginning() const;
    
    };
    
    template 
    Pointer::Iterator> BinaryTree::GetBeginning() const
    {
        return Pointer::Iterator>();
    }
    

提交回复
热议问题