Nov 6, 2009 at 6:18pm UTC
Line 34: you should call delete [] num
What problems does it give you?
Nov 6, 2009 at 6:22pm UTC
there is an error in line 18
and if i remove this line the prog will give me run time error
plz i want to u to handle up the problem coz i really want to know what is the problem
Nov 6, 2009 at 6:24pm UTC
What are you trying to do on line 18 anyway? I don't get that line either...
Nov 6, 2009 at 6:25pm UTC
As well, in case this is a simplified code, your non-parametrized constructor is invalid. You're telling it to add +1 to counter, which hasn't been given an initial value. And I don't see the use of counter--
in the destructor, given how you lose that value anyways and one shouldn't call the destructor explicitly.
Nov 6, 2009 at 6:31pm UTC
this code runs well but i want to use a dynamic array but i cant help me
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
# include <iostream>
using namespace std ;
class NumList {
private :
static int counter ;
int num[5] ;
int size ;
public :
NumList( int , int [5] );
void display() ;
NumList () ;
~NumList () ;
};
NumList::NumList()
{
counter ++ ;
}
NumList::~NumList()
{
counter-- ;
}
NumList::NumList(int s ,int arr[] )
{
size=s;
for ( int i=0 ; i < size ; i++ )
{
num[i] = arr[i] ;
}
}
void NumList::display()
{
for ( int i=0 ; i < size ; i++ )
{
cout << num[i] << endl ;
}
}
void fun ( NumList numList )
{
numList.display () ;
}
int NumList:: counter = 0 ;
int main ()
{
int arr[3] = {1111, 2222, 3333};
NumList numList(3, arr);
numList.display();
cout << " -------------------------------- " << endl ;
fun( numList );
cout << " -------------------------------- " << endl ;
numList.display();
cout << " -------------------------------- " << endl ;
system("pause" ) ;
return 0 ;
}
i want to use a dynamic array and make the prog run plz help me to learn
Last edited on Nov 6, 2009 at 6:31pm UTC
Nov 6, 2009 at 10:42pm UTC
In the dynamic one, you are calling an unexisting constructor on line 18
And line 7 should be int * num;