Heres the code:
#include <cstdlib> #include <iostream> using namespace std; class classA { protected: void setX(int a); private: int p; }; classA:: classA() { //error here. p = 0; } void classA:: setX(int a) { p = a; } int main() { system("PAUSE"); return EXIT_SUCCESS; }
Destructors are implicitly called when an automatic object (a local object that has been declared auto or register , or not declared as static or extern ) or temporary object passes out of scope. They are implicitly called at program termination for constructed external and static objects.
The "private within this context" error refers to the fact that the functions addShipment , reduceInventory and getPrice are not members or friends of the class Product , so they cannot use its private members.
You forgot to declare the constructor in the class definition. Declare it in public
section of the class (if you want clients to create instance using it):
class classA { public: classA(); // you forgot this! protected: void setX(int a); private: int p; };
Now you can write its definition outside the class which you've already done.
class classA { protected: classA(); // you were missing an explicit declaration! void setX(int a); private: int p; }; classA:: classA() { p = 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With