C++ Logo


Advanced search

Subject: is this valid static const reference
From: spsaxena (mail2spsaxena_at_[hidden])
Date: 2020-07-08 19:55:09

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;

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups