Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.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++ - Fatal编程技术网

C++ 不';是否将文本从函数输出到控制台?

C++ 不';是否将文本从函数输出到控制台?,c++,C++,为什么我的GetMeshLocation()函数不向它输出一个嵌套函数Print(),其中的文本对象位置是(23x,61y,80z)? 编译器成功通过 #include <iostream> class Mesh { public: void GetMeshLocation() { Print("Object location is (23x, 61y, 80z)."); return; } con

为什么我的
GetMeshLocation()
函数不向它输出一个嵌套函数
Print()
,其中的文本对象位置是(23x,61y,80z)? 编译器成功通过

#include <iostream>

class Mesh
{
public:
    void GetMeshLocation()
    {
        Print("Object location is (23x, 61y, 80z).");
        return;
    }
    const void Print(const std::string print)
    {
        std::cout << _print << std::endl;
        _print = print;
        return;
    }
private:
    std::string _print;
};

int main()
{
    setlocale(0, "");
    Mesh myMesh;
    myMesh.GetMeshLocation();

    std::cin.get();
    return 0;
}
#包括
类网格
{
公众:
void GetMeshLocation()
{
打印(“对象位置为(23x,61y,80z)”;
返回;
}
常量无效打印(常量标准::字符串打印)
{

std::cout您正在使用一个在使用后初始化的变量,直到它为空。因此,您需要使用以下语法:

_print = print;
在方法中使用
cout
语句之前,方法应如下所示:

const void Print(const std::string print)
{
    _print = print;
    std::cout << _print << std::endl;
    return;
}
const void打印(const std::string打印)
{
_打印=打印;

std::cout
\u print=print;
那是在
\u print
已经被打印出来之后出现的。哦,谢谢!只有我会犯这样一个可耻的错误:)犯错误的不止你一个人,@quely-我们偶尔都做过类似的事情。