473,497 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

__property

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;
};
Nov 17 '05 #1
6 2280
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 ?

<.> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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;
};

Nov 17 '05 #2
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.


<.> wrote in message news:OL**************@tk2msftngp13.phx.gbl...
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 ?

<.> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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;
};


Nov 17 '05 #3
.. wrote:
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.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #4
.. wrote:
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; }
}
};

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #5
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?

"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
. wrote:
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; }
}
};

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

Nov 17 '05 #6
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.
"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:Or**************@TK2MSFTNGP12.phx.gbl...
. wrote:
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.

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

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4785
by: | last post by:
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our term to dump Borland (not only BCB). As a part of my attempt to dump long-loved BCB I'm trying to investigate how one can ...
2
2291
by: Daniel Lidström | last post by:
Hi, I would like to know the cleanest way to change the serialization of my Line class from: <Line staStart="2327.02" length="10.00000003390744"> <End>549016.570965 57945.741122</End>...
0
1049
by: Edward Diener | last post by:
Since a __property can be split between a read access and a write access property in MC++, how does one set an attribute on a __property ? Is setting an attribute before either the read access...
4
1083
by: | last post by:
Hi, If I make a __gc type with __property set and get I set them to private:, those 2 methods are private ok but the actual generated property is public according to the object browser yet its...
3
1338
by: Julie | last post by:
What would you expect from the following: enum Type { a, b, c }; public __gc class MClass { public: MClass(Type t); __property void set_Type(Type t); // etc.
0
799
by: Carl | last post by:
I started using managed C++ properties the standard way. E.g. __property void set_Value (Double Value) { m_Value=Value; } __property bool set_Value (Double Value) { if ( Value < 0 ) return...
9
2146
by: Christian Kaiser | last post by:
Hmmm. I just got the following compiler messages: test_cpp.cpp d:\src\logsolar\datasources\test_cpp\test_cpp.h(18) : error C3760: please use __property keyword to declare property in managed...
2
4216
by: Mark Ingram | last post by:
Hi, can anyone tell me why I'm getting the following error: error C4980: '__property' : use of this keyword requires /clr:oldSyntax command line option & error C3813: a property declaration...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.