Writing VB style using C++ is a shame to you and this violate C++ god programming techniguqes and pricinples.
You better familiar yourself with C++ rather than request a shortcut.
Printable View
Writing VB style using C++ is a shame to you and this violate C++ god programming techniguqes and pricinples.
You better familiar yourself with C++ rather than request a shortcut.
The thing is, in a typical C++ program such data would be private.Quote:
Originally Posted by Neolisk
You would not be thinking about the individual data items, but about the button as a whole. Instead of writing to individual data members, you would have functions which change the state of the button:
Code:btnButton->SetText(someText, someForeColor, someBackColor);
Code:
I have not come across keyword "with" in C++ associated with structures and class.
Even if it is provided I will avoid using it.
struct MyStruct
{
int nAge;
int nGrade;
};
void Function()
{
MyStruct obj;
int nAge;
int nTempGrade;
/* will below code result in obj.nAge = nAge or nAge = obj.nAge = nAge */
with obj
{ /* or begin */
nTempGrade = nGrade;
nAge = nAge;
} /* or end */
}
A taste-related thing, depends on the programmer. Also helps resolving unlikely ambiguity for intellisense.Quote:
Originally Posted by JohnW@Wessex
I have actually, but it doesn't help.Quote:
Originally Posted by srelu
You know, it's man's privilege to develop new things through a perspective of what he already knows. Well, that's exactly what I'm trying to do.Quote:
Originally Posted by Peter_APIIT
Have you ever worked with a Button class? :)Quote:
Originally Posted by Zaccheus
It is probably private in VB as well. Those are properties. All this if I recall what I used to do 5 years ago. :)Quote:
Originally Posted by Zaccheus
Yes, in fact I've helped to write one which is used in commercial software. ;)Quote:
Originally Posted by Neolisk
In that case the 'with' construct would not work anyway, because C++ does not have properties.Quote:
Originally Posted by exterminator
How about this?Quote:
Originally Posted by Neolisk
Closest you're going to get, but this sort of thing can certainly clarify code in many situations.Code:{
Button &B = *this->btnButton;
B.Text =
B.ForeColor =
B.BackColor =
}
I just remembered VB code designer generated code, which is 'friend withevents...'. So yes, they might be private and still be able to use directly. Actually, I don't know exactly if they are. But it doesn't depend on whether they are properties or not. And it certainly doesn't depend on whether you're using VB or C. Well, I doubt any of them uses a different Button class apart from what's defined in Windows.
Lindley: I already understood the possible solution, originally suggested by Paul, so there is not need to duplicate it.
Zaccheus: Well, I just asked, because I found it curious that you didn't refer to the button directly as it's the usual way for me. So I write like ButtonName.Text = "123", and not something like ButtonName.SetText("123", enumJustPlainText, enumNoDontDisplayMessageBoxes, ... other things) to add text to a button. :)
His example used a pointer, I believe. I was merely demonstrating that references work just as well in these cases.Quote:
Originally Posted by Neolisk
There is a subtle difference in that Lindley is using a reference instead of a pointer,Quote:
Originally Posted by Neolisk
which is probably better if you want to create an alias to a member.
See, everyone's always repeating each other....no big.
Sorry, didn't notice the difference. :)
Thanks for the hint.
We made removal of unnecessary this-> part of our coding standards. People weren't using it for any good reason apart from getting intellisense to list the class members and then forgetting to delete the this-> part afterwards.Quote:
Originally Posted by Neolisk
Also I had the job of writing the standards! :D. Nobody else minded the rule.
I have to agree, If I had to read someones code with this-> all over the place and unnecessary alias, I would be annoyed
It matters a lot. You never want to be directly manipulating the data members in a non-trivial class. Properties are get and set functions with a nicer syntax, which means you are not directly manipulating the data members.Quote:
Originally Posted by Neolisk
C++ does not have properties, so it would certainly depend on what you are using.Quote:
Originally Posted by Neolisk
What's defined in Windows is the Windows API, which is very different from the VB Button example you gave.
Like I said above, C++ does not have properties.Quote:
Originally Posted by Neolisk