Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


C++ Class Properties?

This topic is 6674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can you do this in C++? If so how? For Example (in Delphi):
  TSomeClass = class
    property Name : string read GetName() write SetName();  
    function  GetName() : string;
    procedure SetName(s : string);
procedure SomeProcedure();
  mySomeClass : TSomeClass;
  mySomeClass := TSomeClass.Create;

  mySomeClass.Name := ''Some Class Name'';

When "Some Class Name" is assigned to the TSomeClass.Name property it is passed through the private procedure TSomeClass.SetName(). When you read from TSomeClass.Name it gets the value from the private function TSomeClass.GetName(). Can anyone tell me how this is done in C++? Or if it is possible at all? Thanks.

Share this post

Link to post
Share on other sites
class TSomeClass
public :
char Get_Name() ;
bool Set_Name(char Data[20]) ;
private :
char Name[20] ;
} ;

char TSomeClass::Get_Name()
return(Name) ;

bool TSomeClass::Set_Name(char Data[20]) ;
if(strcpy(Name, Data)
return(true) ;
return(false) ;
void SomeProcedure()
// Local variables
TSomeClass mySomeClass ;

// Code
mySomeClass.Set_Name(Some Class Name) ;
// When you leave the function the class will delete itself
I think thats how you do it
I''m sure people will blast me if I''m wrong

Share this post

Link to post
Share on other sites
Defining properites is not possible in official ANSI C++ (as far as I know), but C++ Builder has some language extensions that make it possible. Pretty logical, since both Delphi and C++ Builder are Borland (or Inprise, whatever ) products. I can''t remember exactly how to do it, but it''s pretty much the same as in Delphi.

Twig Meister: if you want your code to have a nifty layout put it between [ source ] and [ /source ] (without the spaces). Like this:
#include <iostream>

using namespace std;

int main()
// Output some stuff

cout << "Blabla" << endl;
return 0;


Share this post

Link to post
Share on other sites
Thanks everyone for the response, that was exactly what I was looking for Shinkage. Too bad it isn''t cross-platform/compiler

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!