簡體   English   中英

output 文本不是從 function 到控制台嗎?

[英]Doesn't output text from function to console?

Why doesn't my GetMeshLocation() function output a nested function to it Print() with the text Object location is (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;
}

該代碼是為練習目的而編寫的,沒有任何用處:)

您正在使用一個在使用后初始化的變量,直到它為空。 因此,您需要輸入以下語法:

_print = print;

在方法中使用cout語句之前的方法應該是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM