Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Properties

Status
Not open for further replies.

MarkRuse

Programmer
Aug 11, 1999
29
0
0
GB
Hi,

I have created a Class for a DLL as follows :

Class Test
{
public:

private:
long lng_Variable;
}

I can write a method to give access to the lng_Variable, but I would prefer to write a Property so that my clients can write things like :

Test Tester;
Tester.Variable = 4;

instead of Tester.Variable(4);

How do I go about writing properties within C++ ?

Thanks

Mark
 
You should be able to create a variable in public

long Variable;

Then assign it a default in the constructor

Variable = 3;

Then you should be able to change it by:
Test Tester;
Tester.Variable = 4;

Should work.
B
 
Wow, if your going to violate prime tenets of Object Oriented Design in your classes then why use a language like C++ in the first place. You may as well use Visual Basic.

"But, that's just my opinion... I could be wrong".
-pete
 
;-)

Has anybody else got ant ideas ? I could use ATL to give me properties via COM, but are there any other ways ?

Mark
 
Mark,

Have you used ATL with COM objects in C++?

Look at the interface to ADODB.Recordset in the .tlh file created by the #import statement. There are no properties, just get and set methods.

-pete
 
I have a good idea. If the function return type is a reference to long, you could write:
------------------------
#include<iostream.h>
int&amp; one_function(int xx=0)
{
int&amp; x=xx;
return x;
}
void main()
{
int y;
y=one_function()=1;
cout<<y;
}
------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top