I've tried to do a reference to a member variable, and understood that it does not work. Are there any way to do this? If not, is there a way to not constantly write "(* this)." ?
#include <iostream>
#include <string>
class Test
{
private:
std::string str_m;
void doSomething()
{
std::string& str = (*this).str_m; // does not work
std::cout << str << '\n';
}
public:
Test(std::string str): str_m(str)
{
(*this).doSomething();
}
};
int main()
{
Test test{"aaa"};
return 0;
}
VS compiler gave me: error C3867: 'Test::doSomething': non-standard syntax; use '&' to create a pointer to member