const ?
, , "" . . ( )
, , , .
, , .
125 0, :
#include <alloca.h>
#include <cstring>
#include <iostream>
struct Foo
{
double const& f;
Foo(double const& fx) : f(fx)
{
std::cout << fx << " " << this->f << std::endl;
}
double GetF() const
{
return f;
}
};
Foo make_foo()
{
return Foo(123.0 + 2.0);
}
int main()
{
Foo p = make_foo();
void * const stack = alloca(1024);
std::memset(stack, 0, 1024);
std::cout << p.GetF() << std::endl;
return 0;
}
0!
125.0 2.0 . rvalue, Foo, Foo double. .
, , , , Foo . , Foo, .
, , () . , , ( alloca memset), () , , . , segfault .
make_foo alloca std:: memset - , , "stack", , :
Foo p = Foo(123.0 + 2.0);
std::vector<unsigned char> v(1024, 0);
std::cout << p.GetF() << std::endl;