Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

constructor destructor problems

 
webmaster forum
nik5388  Offline
Activity
0%
 
New Poster
Posts: 1
Topics: 1
October 06, 2009, 07:28:33 AM

This is a small program so i have pasted all of it..The problem it  is stating is that the count is undeclared in both the constructor & destructor...but i have already globaly deaclred it...need help..thanks..with an explanation..



Code:
#include<iostream>
using namespace std;
int count=0;
class alpha
{
      public:
             alpha()
             {
                    count++;
                    cout << "no of objects created" << count;
                    }
                    ~alpha()
                    {
                            cout << "no of objects destoryed" << count;
                            count--;
                            }
                            };
                            main()
                            {
                                  cout << "Enter main";
                                  alpha a1,a2,a3,a4;
                                  {
                                  cout << "Enter block1";
                                  alpha a5;
                                  }
                                  {
                                        cout << "Enter block2";
                                        alpha a6;
                                        }
                                        cout<< "Re-enter main";
                                        system ("pause");
                                        }
« Last Edit: October 20, 2009, 06:19:10 PM by Thomas »
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
October 26, 2009, 04:50:58 AM

Your code layout is very poor - remove indentation when you come to the end of a block (} brace) otherwise it gets very confusing.

Not a C++ programmer, but try putting count in the class rather than globally

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page January 25, 2012, 03:42:43 PM