__property

G

Guest

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;
};
 
G

Guest

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 ?
 
G

Guest

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.
 
B

Brandon Bray [MSFT]

.. said:
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.

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.
 
B

Brandon Bray [MSFT]

.. said:
Why cant we have C# style property set and get inside a function? Too
complex? Couldnt this be done via a Switch?

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; }
}
};
 
G

Guest

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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top