Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to convert C# get,set code to C++

Tags:

I have the following code in C#:

public string Temp         {             get { return sTemp; }             set {                  sTemp = value;                 this.ComputeTemp();             }         } 

Is it possible to convert this and use the get and set this way? I know that you cannot declare like so and I need the ":" to declare but when I try to do this:

public:         std::string Temp         {         get { return sTemp; }         set {                  sTemp = value;                 this.ComputeTemp();             } 

The error I receive is on the first "{" stating expected a ';'. Any suggestions on how to fix it?

like image 889
user2577497 Avatar asked Jul 30 '13 19:07

user2577497


People also ask

Can we convert C++ to C?

It is possible to implement all of the features of ISO Standard C++ by translation to C, and except for exception handling, it typically results in object code with efficiency comparable to that of the code generated by a conventional C++ compiler.

What is type conversions in C?

In C programming, we can convert the value of one data type ( int, float , double , etc.) to another. This process is known as type conversion.

Which conversion is not possible?

Which type of conversion is NOT accepted? Explanation: Conversion of a float to pointer type is not allowed.

Can we convert int to double in C?

The %d format specifier expects an int argument, but you're passing a double . Using the wrong format specifier invokes undefined behavior. To print a double , use %f .


1 Answers

Are you using C++/CLI? If so this is the property syntax

public:   property std::string Temp {      std::string get() { return sTemp; }     void set(std::string value) { sTemp = value; this->ComputeTemp(); }    } 

If you are trying to use normal C++ then you are out of luck. There is no equivalent feature for normal C++ code. You will need to resort to getter and setter methods

public:   std::string GetTemp() const { return sTemp; }    void SetTemp(const std::string& value) {      sTemp = value;     this->ComputeTemp();   } 
like image 176
JaredPar Avatar answered Oct 09 '22 02:10

JaredPar