Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > visual c > february 2004 >

visual c : __property



Brandon Bray [MSFT]
2/19/2004 2:34:16 AM
[quoted text, click to view]

The assumption is that the property should be public because code outside of
the class may want to access the property. Choosing the visibility of the
property depends on the situation.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Brandon Bray [MSFT]
2/19/2004 2:36:21 AM
[quoted text, click to view]

The new C++ syntax coming in the Whidbey release of Visual C++ does make
properties cleaner. Consider the following:

ref class R {
private:
int x; // Backing field

public:
property int X {
int get() { return x; }
void set(int val) { x = val; }
}
};

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

<.>
2/19/2004 10:36:48 AM
With the below example (taken from MSDN)..

This also makes visible the set_Size and get_Size methods, and generates
the Size property as we normally see it.

Why didnt the get_ and set_ methods be private like the rest so just the
Size property thats generated is visible? Doesnt make sense to have them
visible.



__gc class MyClass
{
public:
MyClass() : m_size(0) {}
__property int get_Size() { return m_size; }
__property void set_Size(int value) { m_size = value; }
// compiler generates a pseudo data member called Size
protected:
int m_size;
};

<.>
2/19/2004 10:44:04 AM
Why cant we have C# style property set and get inside a function? Too
complex? Couldnt this be done via a Switch?

I just dont like having 3 visible points for manipulating a property when
there should only be one VISIBLE.

Just set it to private maybe ?

[quoted text, click to view]

<.>
2/19/2004 11:00:38 AM
I set them to private but this geneated property is public. Isnt this a bad
way to handle properties in the language?

I declare them private yet the generated one is public. I just want the
generated one public and the other 2 methods that shouldnt be called
private.

This is a bad KLUDGE. Yet another C++ kludge.




[quoted text, click to view]

<.>
2/19/2004 11:49:04 AM
Nice but stop using whidbey syntax dammit.

i assume ref class == public __gc class blah ?

So, if I make the get_ and set_ private thats ok, it wont affect the
generated Blah property thats visible?

Would it be possible to set the visibility of the set_ and get_ propertys so
I can have set_ as internal and get_ as public etc?



[quoted text, click to view]

<.>
2/19/2004 7:11:08 PM
Yeah but If I set the get_ and set_ to private the property it generates is
set to public. That way they have a single way to access this and not 3.


[quoted text, click to view]

AddThis Social Bookmark Button