我知道用C编码,函数的返回值使用%eax寄存器返回给调用者.
使用c ++,也可以返回结构而不仅仅是'Primitive'类型,所以当一个函数返回一个结构时,存储的返回值在哪里(堆栈,堆等)?
示例代码:
class Student
{
private:
int m_id;
public:
Student(int id)
{
m_id = id;
};
~Student();
int getId()
{
return m_id;
};
};
Student myFunc()
{
return Student(123);
}
int main()
{
//How does 'student1' get the value from the function?
//Does 'myFunc' write directly to the stack of main?
Student student1 = myFunc();
return 0;
}
Run Code Online (Sandbox Code Playgroud)