Using a class method to assign a value to a private member.

Folks, I am trying to use a method within a class to assign a value to a private member of that class. I can't figure this out to save my hind-parts. Can anyone please point ou tthe obvious?


#include <cstdlib>
#include <cstdio>

using namespace std;

class NoClass {
public:
NoClass() { };
NoClass(const NoClass& orig) { };
virtual ~NoClass() { };
void SetAnInt() {
this->anInt = ???;
}
int GetAnInt() {
return this->anInt;
}

private:
int anInt;
};
int main(int argc, char** argv) {

NoClass *nc = new NoClass();
nc->SetAnInt() = 133; // Important part here
printf("%d\n", nc->GetAnInt());
return 0;
}
class foo
{
private:
int x;
public:
void setx(int val) {x = val;}
}


foo f;
f.setx(3);

Topic archived. No new replies allowed.