Clang VS VC++:“error: declaration of 'T' shadows template parameter”

后端 未结 1 767
情话喂你
情话喂你 2020-12-31 16:31

I was trying to compile the following code for the classic copy&swap idiom on my Mac with clang 3.3

template class node{

private:
             


        
1条回答
  •  臣服心动
    2020-12-31 17:12

    I believe that this is what you want (which happens to be what you just added to your question as the third option)

    #include 
    
    template  class node;
    template  void swap(node & a, node & b);
    
    template class node {
        private:
            node* left;
            node* right;
            T value;
    
        public:
            friend void swap<>(node&, node&);
    };
    
    template  void swap(node & a, node & b) {
        std::swap(a.left, b.left);
        std::swap(a.right, b.right);
        std::swap(a.value, b.value);
    }
    
    int main() {
        node x, y;
        swap(x, y);
    }
    

    0 讨论(0)
提交回复
热议问题