为什么返回类型的返回(str)是字符串&

时间:2017-01-21 02:15:35

标签: c++ c++14 decltype

来自https://isocpp.org/wiki/faq/cpp14-language

from tkinter import *
root = Tk()
canvas = Canvas(root)

def create_button(location_name, position_x, position_y):
    Button(root, text = location_name).place(x=position_x, y=position_y, width=60, height=20)

a = create_button("A",20,30)
b = create_button("B",70,80)

canvas.grid()
root.mainloop()
  

第一个返回string lookup1(); decltype(auto) look_up_a_string_1() { auto str = lookup1(); return str; } decltype(auto) look_up_a_string_2() { auto str = lookup1(); return(str); } ,第二个返回string,这是一个   引用局部变量string &

为什么str会返回look_up_a_string_2

0 个答案:

没有答案