🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Size doesn't really matters...right?

Started by
54 comments, last by JoeJ 6 years, 9 months ago
2 minutes ago, MarcusAseth said:

int don't have member functions, it can't be the case :\

You cannot invoke a function on a primitive type. So you cannot actually replace it by a.operator=(6);

But you at least agree to see an assignment:

int a = 5;

a = 6;

🧙

Advertisement
3 minutes ago, matt77hias said:

You cannot invoke a function on a primitive type.

Well then it seems you agree with my point, you can't invoke a function like in the string example


f(a).operator=(b);

and that's why it doesn't compile in that instance for the int

3 minutes ago, MarcusAseth said:

Well then it seems you agree with my point, you can't invoke a function like in the string example



f(a).operator=(b);

and that's why it doesn't compile in that instance

but you do not call operator=

you do f(a) = b where f(a) returns an int value, which is exactly the same case as 5 = b;

Constant primitives such as 1,2u, 3f, 4d, 'c' are immutable, meaning that they are always implicit const.

 

__128 is a built-in type as well for MVC++ compiler (i.e. Visual Studio), you can overload operators for that type if they are not already defined:

__m128 & __vectorcall operator+=( __m128 &v1, const __m128 &v2);

operator= is defined for all built-in types, you cannot redefine it, you cannot access it.

🧙

5 minutes ago, matt77hias said:

but you do not call operator=

you do f(a) = b where f(a) return an int value, which is exactly the same case as 5 = b;

Yes I get that, you get an rvalue as return in the int case so you can't assign to it.

I am just pointing out the reason why you can in the string example even though you are still returning an rvalue to a string.

And the reason is :

Quote

An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can
also be used to modify its referent under certain circumstances. [ Example: a member function called for an
object (9.3) can modify the object. — end example ]

which means string is doing this:


f(a).operator=(b);

So...I am not sure what part of this is not convincing you... :\

1 minute ago, MarcusAseth said:

So...I am not sure what point of this is not convincing you... :\

It is about objects, int is not an object. If you wonder about operator overloading for primitive types look above at my __m128 example.

🧙

Just now, matt77hias said:

It is about objects, int is not an object.

Yes, and I am talking of string all along, which is an object.

Seriously Matt, I am often getting the impression that you misunderstand me on purpose... x_x

rvalue reference = lvalue

 

int f(int &n) { return n; }

f(a) = 5;

 

string f(string &n) { return n; }

f(a) = "5";

 

std::string &operator=(std::string &)

-> you invoke this method on a lvalue (rvalue reference)

 

 

🧙

12 minutes ago, matt77hias said:

rvalue reference = lvalue

I don't know what am I suppose to make of this statement...


string f(string& n)

for what I know, the string returned by value in the function above means you are constructing a string using wathever you return from inside the function, this means that the new constructed string is an rvalue and not an rvalue reference.

And thus to me seems in line with what I quoted in the posts above, which is 

Quote

an rvalue of class type can also be used to modify its referent under certain circumstances. [ Example: a member function called for an object

so...I still don't get it what do you think is wrong with this.

Lets try some other approach...

 

Is the behavior you are talking about different between C++98 and C++11/C++14? No, it isn't.

So how can you use lvalue/rvalue terminology in your argumentation? C++98 does not differentiate between lvalue and rvalue types.

 

🧙

3 minutes ago, matt77hias said:

Lets try some other approach...

 

Is the behavior you are talking about different between C++98 and C++11/C++14? No, it isn't.

So how can you use lvalue/rvalue terminology in your argumentation? C++98 does not differentiate between lvalue and rvalue types.

 

seriously, I don't know nor care for C++98, this other aproach won't work... whatever the point you're trying to make is, you're only obfuscating it more, since I still have no idea about what you think is wrong with my post above... 

This topic is closed to new replies.

Advertisement