0

How would I do this

class test {
    public:
        int* num;
    };

int main() {
    test *d = new test;
    d->num = new int;
    d->*num = 3;
cout << d->*num;
}
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ProgrammingGeek
1

Try something like this

#include <iostream>

class test {
    public:
        int* num;
    };

int main() {
    test *d = new test;
    d->num = new int;
    *(d->num) = 3;
  std::cout << *(d->num);
}
Votes + Comments
thanks
1
#include <iostream>

class test {
    public:
        int* num;
    };
 
int main() {
    test *d = new test;
    d->num = new int;
    *d->num = 3;
    std::cout << *d->num;
}

Edit: Beaten to the punch by seconds!

Edited by Moschops: n/a

Votes + Comments
thanks anyway!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.