0
How can I make class return value like function without brackets
There is one thing I'm interested in, how to make something like get/set from c# in c++, there is way to do that, we can see it on class string, anyone know how? Example: class A{ int x; public: A(int x){ this->x=x; } char* a(){ return "I'm A"; } } int main(){ A a = 5; // call constructor A(int x) cout<<a.a; // get char* from a() }
4 ответов
+ 1
C++ doesn't have getters and setters like JavaScript or C#.
You just have to call the methods as functions
0
And how does string work?
This code works and it's almost what I'm asking about
#include <string>
int main(){
string str = "text";
}
0
Ok, part of solution is using:
void operator=(int x){...}
however, this doesn't work on:
A a = 1;
only:
A a;
a = 1
0
I've got it, string is defined like this:
typedef char* string;