By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

how to make a program that have a constructor and destructor and one member variable

P: 3
i can't make a program that have a constructor and destructor and one member variables and one static member variables
Mar 17 '07 #1
Share this Question
Share on Google+
1 Reply


Ganon11
Expert 2.5K+
P: 3,652
You mean a class? What's wrong with:

Expand|Select|Wrap|Line Numbers
  1. class myTestClass {
  2.    private:
  3.       int someData;
  4.  
  5.    public:
  6.       myTestClass(int x);
  7.       ~myTestClass();
  8.       int getData() const;
  9.       static void doStuff();
  10. };
  11.  
  12. myTestClass::myTestClass(int x) {
  13.    someData = x;
  14. }
  15.  
  16. myTestClass::~myTestClass() {
  17.    // Stuff
  18. }
  19.  
  20. int myTestClass::getData() {
  21.    return someData;
  22. }
  23.  
  24. /* static */ void myTestClass::doStuff() { // Might need the static, might not
  25.   // Additional stuff done here
  26. }
Obviously, you'd need to change it to suit your needs, but there shouldn't be any serious problems with this declaration.
Mar 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.