what is the m()->v

On reading one's C++ code, wondering what exactly the below means (without yet finding his code line on m declaration/definition)

 
    m()->value


as we know
m->value
value is got as member of m, by referencing, start with reference m as pointer

but explain that asked, thanks before
Last edited on
Possibly, POSSIBLY(!), this is just a SWAG, it is a function/class method returning a pointer to an class/struct object that contains a data member called value.

To really give an answer that is more than just a guess would require seeing a lot more of the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

struct S
{
	int value;
};

S* m()
{
	static S m{5};
	return &m;
}

int main()
{
	// alternative 1
	std::cout << m()->value << "\n"; // prints 5
	
	// alternative 2
	S* ptr = m();
	std::cout << ptr->value << "\n"; // prints 5
}
Would this's supposed to do or perform

static S m{5};

? What is the {} operator for?
Last edited on
What is the {} operator for?

It's "uniform initialization," added to C++11.

https://mbevin.wordpress.com/2012/11/16/uniform-initialization/

I just wanted to have an object to return a pointer to. If you want you can ignore the code inside m(). The important thing to note is that it returns a S*.
Last edited on
Registered users can post here. Sign in or register to post.