Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't void{} exist?

Tags:

c++

c++17

I am wondering why void() is a prvalue of void but void{} does not exist...? See the following answer: https://stackoverflow.com/a/37708167/293195

For example in the context:

template<typename R>
R foo(){
 return R{};
}
like image 939
Gabriel Avatar asked Nov 12 '18 14:11

Gabriel


People also ask

What is a void object in C++?

void (C++) If a pointer's type is void* , the pointer can point to any variable that's not declared with the const or volatile keyword. A void* pointer can't be dereferenced unless it's cast to another type. A void* pointer can be converted into any other type of data pointer.

Can a variable be a void type?

Initializing a variable without a specified type with a function that doesn't return will infer the variable type to be void .


1 Answers

CWG 2351, resolved in June, has made void{} legal.

like image 65
cpplearner Avatar answered Oct 07 '22 08:10

cpplearner