This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Properties In MSVC6
  Submitted by



Hi folks ...

some days ago i was searching for something in the msdn. i didn't found what i want but i found something else. a feature also supported by Delphi, C++ Builder and also the upcoming C#. Properties. Sadly this is MSVC++ specific. You can use Properties by using the __declspec property Keyword. look @ this example.

class CBsp
{
	public:
		int Get()
		{
			// maybe calc new value
			return m_iTest;
		}
		void Set( int iNew )
		{
			// maybe performce checks .. do a assert .. and and and 
			if( i  10 ) i = 10; // ie.
			m_iTest = iNew;
		}

__declspec( property ( get = Get, put = Set ) )int iTest;

private: int m_iTest;

};



.. so u can do

CBsp demo;

demo.iTest = 12; if( !demo.iTest == 10 ) { // this will never happen .. ( hope so ); }

the compiler finds every occurence of the member "iTest" .. and replace it with the Access functions Get/Set. There u can perform checks ect. I think this make the code more compact & readable. ( yes .. the declaration is a lil bit wired )

That's all for now ...


The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.