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?
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.
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 type of conversion is NOT accepted? Explanation: Conversion of a float to pointer type is not allowed.
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 .
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With