C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2006, 10:44 PM   #1
The Right Honourable
 
psychopath's Avatar
 
Join Date: Mar 2004
Location: Where circles begin.
Posts: 1,068
C++/CLI Property

Suppose I declare some variables in a class...
Code:
public:
	String ^name;
	int ilImageName;
	int id;
	TEX_TYPE type;
	TEX_FORMAT format;
I can set these variables in the class and whatnot. However, I can also create property types to set these class varibles, like this:
Code:
protected:
	String ^name;
	int ilImageName;
	int id;
	TEX_TYPE type;
	TEX_FORMAT format;

public:
	property String ^Name{
		String ^get() { return(name); }
		void set(String ^value) { name = value; }
	}
		property int ID{
		int get() { return(id); }
		void set(int value) { id = value; }
	}

	property TEX_TYPE Type{
		TEX_TYPE get() { return(type); }
		void set(TEX_TYPE value) { type = value; }
	}

	property TEX_FORMAT Format{
		TEX_FORMAT get() { return(format); }
		void set(TEX_FORMAT value) { format = value; }
	}
My question here is; is there any real point to using properties? And if not this, what exactly would you use properties for?

Thanks.
__________________
Memorial University of Newfoundland
Computer Science

Mac and OpenGL evangelist.
psychopath is offline   Reply With Quote
Old 07-11-2006, 11:08 AM   #2
The Right Honourable
 
psychopath's Avatar
 
Join Date: Mar 2004
Location: Where circles begin.
Posts: 1,068
Sorry about putting this in the wrong forum first. I wasn't sure whether to put it here in the Windows forum, or in the C++ forum. At least i'll know for next time.
__________________
Memorial University of Newfoundland
Computer Science

Mac and OpenGL evangelist.
psychopath is offline   Reply With Quote
Old 07-11-2006, 11:42 AM   #3
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,812
I think all of us are trying to figure out just where to put CLI. I know where I'd like to 'put' it.
__________________
If you aim at everything you will hit something but you won't know what it is.
Bubba is offline   Reply With Quote
Old 07-11-2006, 04:22 PM   #4
Registered User
 
Join Date: Jun 2006
Posts: 30
The good thing about properties is that you can do additional processing of values that users store or retrieve. For example, say you have a property called Age. If you would make Age a public member, then any value could be stored there, which might lead to errors. You don't want people to store negative values there or numbers like 1560. So your Set() function might look something like this:
Code:
void Set(String^ value) {
     if (value < 0 || value > 120)
          value = 0;
     age = value;
}
This is as simple as it can get. In a more a complex applications, there would always be need for checking of values and additional processing.
Newbeee is offline   Reply With Quote
Old 07-11-2006, 05:04 PM   #5
The Right Honourable
 
psychopath's Avatar
 
Join Date: Mar 2004
Location: Where circles begin.
Posts: 1,068
So it's basically like writing a custom handler for variable assigment?

If so, then in my particular case, shown in my first post, using properties would probably be overkill, since I have no need of additional processing.
__________________
Memorial University of Newfoundland
Computer Science

Mac and OpenGL evangelist.
psychopath is offline   Reply With Quote
Old 07-11-2006, 09:45 PM   #6
Registered User
 
Join Date: Jun 2006
Posts: 30
That's correct.
Newbeee is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
static property George2 C# Programming 1 06-12-2008 01:03 AM
Problem with a file parser. Hulag C++ Programming 7 03-17-2005 09:54 AM
Creating a modeless property sheet axr0284 Windows Programming 6 01-12-2005 06:29 AM
Dialog Box & Property Sheet :: MFC kuphryn Windows Programming 2 08-01-2002 01:33 PM
Property Sheets :: MFC kuphryn Windows Programming 0 05-09-2002 03:04 PM


All times are GMT -6. The time now is 11:37 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22