+ 1
If you're coder helper, then help me😊
#include <iostream> #include <vector> using namespace std; class Number{ public: int setNumber(){ cin >> num; return num; } friend void infoStreamer(Number *obj); protected: int num; }; class CubeNumber : public Number{ public: int cubeNumber (){ cNum = num*num*num; return cNum; } private: int cNum; }; void infoStreamer(Number *obj){ cout << "Your input: " << obj->setNumber(); } int main() { Number *n; CubeNumber *cn; n->setNumber(); infoStreamer(n); return 0; } Must outputs something, but it doesn't🤔
2 Réponses
+ 1
You have declared pointer n to Number, but don't allocated memory by new Number().
Now you have a pointer to the unknown
+ 1
Oleg Storm you are not doing allocation of Number class pointer.. Just do it as below:
Number* n = new Number;
Or
Number a;
Number* p = &a;