Nick said:
void as a function parameter
#41
Posted 28 May 2006 - 01:42 PM
#42
Posted 28 May 2006 - 01:49 PM
#define this (*this)
About member access: that should definitely NOT change. Or do you think you should always type the fully qualified name for any global as well (e.g., ::mynamespace::myfunction instead of myfunction)? Because they're not so unrelated
-
Currently working on: the 3D engine for Tomb Raider.
#43
Posted 28 May 2006 - 01:49 PM
juhnu said:
Seriously though, I'd love to find one example of currently valid C++ code that would break when 'this' can automatically evaluate to a reference.
#44
Posted 28 May 2006 - 02:02 PM
template<class T> struct thisref_t : public T
{
T * operator -> () { return this; }
};
#define this static_cast<thisref_t<typeof(*this)> &>(*this)
class MyClass()
{
void foo();
void bar()
{
this.foo(); // ok
this->foo(); // ok
}
};
Then again, that would disable the use of an operator-> defined in MyClass
-
Currently working on: the 3D engine for Tomb Raider.
#45
Posted 28 May 2006 - 02:02 PM
Nick said:
Seriously though, I'd love to find one example of currently valid C++ code that would break when 'this' can automatically evaluate to a reference.
Yeah, I'd prefer writing 'this->' over 'self.' too actually. The automatic evaluation to a reference type is an interesting idea. I can't think of any example rightaway where it wouldn't work. 'this' should be a pointer by default, and implicitly casted to a reference when needed.
#46
Posted 28 May 2006 - 02:07 PM
.oisyn said:
and it would have problems when you want to pass 'this'-pointer to a function.
#47
Posted 28 May 2006 - 02:16 PM
bramz said:
..because then the compiler would help in catching some bugs like in this:
struct Foo {
int legCount;
void SetLegCount(int legcount) {
this->legCount=legCount;
}
};
To avoid this I usually use 'p'-prefix for function parameters. Maybe if there was a keyword to define the normal member access or a stricter one for a function?
#48
Posted 28 May 2006 - 02:30 PM
class ABC
{
void doX(ABC *abc);
void doX(ABC &abc);
void doY();
{
doX(this); // Call first or second version?
}
};
So clearly it wouldn't work to have 'this.' syntax with backward compatibility.
#49
Posted 28 May 2006 - 02:39 PM
Nick said:
class ABC
{
void doX(ABC *abc);
void doX(ABC &abc);
void doY();
{
doX(this); // Call first or second version?
}
};
So clearly it wouldn't work to have 'this.' syntax with backward compatibility.That would call the first one as the 'this' would be evaluated as a pointer.
#50
Posted 28 May 2006 - 02:49 PM
Bramz' warehouse | LiAR isn't a raytracer
#51
Posted 28 May 2006 - 03:38 PM
bramz said:
#52
Posted 29 May 2006 - 12:38 PM
Thing is, we can't get it to being a reference exclusively, for obvious reasons. So, if we want it to act as reference, we should give it a dual character of being both a reference and pointer, but that poses ambiguities that confuse matters in a way that's not proportional to the rather mundane problem at hand: being able to write a dot instead of an arrow. Frankly, I hardly ever use the this pointer anyway. Or more correctly: if I do, it mostly is to pass it as an argument to a function. This minor syntantic change is really not worth the troubles ...
Bramz' warehouse | LiAR isn't a raytracer
#53
Posted 29 May 2006 - 01:23 PM
bramz said:
Can you think of a situation where the dual-nature of a this-pointer/reference would cause problems in the existing code?
#54
Posted 29 May 2006 - 01:25 PM
juhnu said:
See above ... operator-> and foo(bar*) + foo(bar&)
Bramz' warehouse | LiAR isn't a raytracer
#55
Posted 29 May 2006 - 01:37 PM
bramz said:
ah yes, the operator-> would be a problem indeed, but foo(bar*)/foo(bar&) wouldn't..... ok I give up ;)
#56
Posted 29 May 2006 - 06:02 PM
my.counter ++; just sounds as good or bad as self.counter ++; (imho, my sound better).
but i don't care about it at all :D and there is no chance because of backwards compatibility..
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
#57
Posted 01 June 2006 - 04:30 PM
Nick said:
Care to explain why? I like my m_ ´s.
#59
Posted 01 June 2006 - 05:52 PM
#60
Posted 01 June 2006 - 06:27 PM
SigKILL said:
I dislike the underscore, my preference would be mMemberVariable and sStaticVariable and such. Unfortunately, the m_ is a coding standard at our company. But on the bright side of things, Visual Assist has the feature to interpret the sequence [m] [shift] as m_
-
Currently working on: the 3D engine for Tomb Raider.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


This topic is locked









