#include "stdafx.h"
#include <iostream>
using namespace std;
class thing{
public:
int stuff, stuff1, stuff2;
void thingy(int stuff, int *stuff1){
stuff2=stuff-*stuff1;
}
}
int main(){
thing t;
int *ptr=t.stuff1;
t.thingy(t.stuff, *ptr);
}
I’ve been practicing classes, and pointers in C++. What i’m trying to do is have the function thingy modify the stuff2 data member in the thing class by passing a pointer to the value of stuff1. How do I go about doing this?
You are creating a variable of type pointer-to-int: if you want a pointer to
t.stuff1, take its address:Then, pass that pointer to your
thing::thingymethod: