C++ Logo


Advanced search

is this valid static const reference

From: spsaxena <mail2spsaxena_at_[hidden]>
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 {
  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);
  return 0;

Received on 2020-07-08 19:58:35