Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 函数中的智能指针_C++_Function_Smart Pointers - Fatal编程技术网

C++ 函数中的智能指针

C++ 函数中的智能指针,c++,function,smart-pointers,C++,Function,Smart Pointers,今天,我在将std::unique\u ptr传递到函数/重载运算符时遇到了问题。例如: HEADER class SpaceMarine{ public: ... friend std::ostream & operator << (std::ostream &exit, const SpaceMarine &SM); private: std::string name_;

今天,我在将std::unique\u ptr传递到函数/重载运算符时遇到了问题。例如:

    HEADER
class SpaceMarine{
   public:
        ...
        friend std::ostream & operator << (std::ostream &exit, const SpaceMarine &SM);

   private:
       std::string name_; 
       .... (some other few parameters)
       std::unique_ptr<armor> armor_; 
标题
太空船{
公众:
...

friend std::ostream&operator您应该简单地解除它的防护(可能之前检查过,它是否有效)


exit您应该简单地解除它的限制(之前可能会检查它是否有效)


exit您应该简单地解除它的限制(之前可能会检查它是否有效)


exit您应该简单地解除它的限制(之前可能会检查它是否有效)



退出智能指针的使用方法与普通指针相同,因此,如果智能指针是“普通”指针,则执行例如
*armor\uuu
操作的方法也一样指针或智能指针。请参见,例如:
armor
armor
?您有两种不同的类型,还是其中一种是复制/粘贴错误?如果您给出完整(但较小)的答案,问题会更容易回答示例演示当您尝试输出
*armor\uuuu
时出现的错误以及完整的错误消息。智能指针可以与普通指针一样使用,因此,如果是“正常”指针,则执行例如
*armor\uuuu
操作的效果相同指针或智能指针。请参见,例如:
armor
armor
?您有两种不同的类型,还是其中一种是复制/粘贴错误?如果您给出完整(但较小)的答案,问题会更容易回答示例演示当您尝试输出
*armor\uuuu
时出现的错误以及完整的错误消息。智能指针可以与普通指针一样使用,因此,如果是“正常”指针,则执行例如
*armor\uuuu
操作的效果相同指针或智能指针。请参见,例如:
armor
armor
?您有两种不同的类型,还是其中一种是复制/粘贴错误?如果您给出完整(但较小)的答案,问题会更容易回答示例演示当您尝试输出
*armor\uuuu
时出现的错误以及完整的错误消息。智能指针可以与普通指针一样使用,因此,如果是“正常”指针,则执行例如
*armor\uuuu
操作的效果相同指针或智能指针。请参见,例如:
armor
armor
?您有两种不同的类型,还是其中一种是复制/粘贴错误?如果您给出完整(但较小)的答案,问题会更容易回答示例演示当您试图输出
*armor\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu'左值为'std::basic_ostream&&'错误:初始化'std::basic_ostream&std:'的参数1:operator@WarmasterMazuran:也许你可以发布
@WarmasterMazuran的重载,它只能在
操作符@Till:error为:error:cannotbind'std::ostream{aka std::basic_ostream}时才能工作'左值为'std::basic_ostream&&'错误:初始化'std::basic_ostream&std:'的参数1:operator@WarmasterMazuran:也许你可以发布
@WarmasterMazuran的重载,它只能在
操作符@Till:error为:error:cannotbind'std::ostream{aka std::basic_ostream}时才能工作'左值为'std::basic_ostream&&'错误:初始化'std::basic_ostream&std:'的参数1:operator@WarmasterMazuran:也许你可以发布
@WarmasterMazuran的重载,它只能在
操作符@Till:error为:error:cannotbind'std::ostream{aka std::basic_ostream}时才能工作'左值为'std::basic_ostream&&'错误:初始化'std::basic_ostream&std:'的参数1:operator@WarmasterMazuran:也许你可以发布

std::ostream & operator << (std::ostream &exit, const SpaceMarine& SM){ 

    exit << ... << *SM.stats_ << !!!!!! << *SM.weapon_; 
    return exit; 
}
std::cout << armor1;
or
std::cin >> weaponb;
std::ostream & operator << (std::ostream &exit, const Armor& arm){
    return exit << "\n" << arm.name_ << "  AR: " << arm.toughness_;
}
exit << ... << *SM.stats_ << *SM.armor_ << *SM.weapon_;