Date: Thu, 9 Jul 2020 08:55:09 +0800
Hi all,
My question is if the following is considered a valid c++ code.
Specifically the creation of static const reference using rvalue.
#include <stdio.h>
#include <string>
#include <assert.h>
class Foo {
public:
Foo() { printf("new foo %p\n", this); }
~Foo() { printf("del foo %p\n", this); }
Foo dup() { printf("dup foo %p\n", this); return *this; }
};
*static const Foo& tempPath(Foo().dup());*
int main() {
printf("ptr: %p\n", &tempPath);
assert(&tempPath);
return 0;
}
My question is if the following is considered a valid c++ code.
Specifically the creation of static const reference using rvalue.
#include <stdio.h>
#include <string>
#include <assert.h>
class Foo {
public:
Foo() { printf("new foo %p\n", this); }
~Foo() { printf("del foo %p\n", this); }
Foo dup() { printf("dup foo %p\n", this); return *this; }
};
*static const Foo& tempPath(Foo().dup());*
int main() {
printf("ptr: %p\n", &tempPath);
assert(&tempPath);
return 0;
}
Received on 2020-07-08 19:58:35