Error While creating a class whose object cant be created on stack but only on Heap?
I tried writing a code to create a class Whose object can only be created on heap but not 
stack . But During Compilation i got some linking error .The code is :-

      # include<iostream>
      # include<stdio.h>
      # include<conio.h>

      using namespace std;

      class Rect
      { 
       int length;
       int breadth;
       Rect();
   
       public :
       Rect & operator = (const Rect&);       
       Rect(const Rect& abc)
       {
         cout<<"in copy const"<<"\n";        
       }
       ~Rect();
       int area_rect()          
       {return length*breadth;}
   
       void set_value(int a,int b);
          
       static Rect* instance()
       {     
         Rect* ptr=NULL;
         ptr=new Rect ;
         return ptr;
       }
     };

    void Rect::set_value(int a,int b)
    {
      length=a;
      breadth=b;
    }
  
    int main()
    {
     
      Rect* a= Rect::instance();
      a->set_value(10,3);
      cout << "area realted to object a : "  << a->area_rect() <<"\n"; 
      Rect* b=a;    
      b->set_value(10,4);
      cout << "area realted to object a : "  << a->area_rect() <<"\n"; 
      cout << "area realted to object b : "  << b->area_rect() <<"\n"; 
      delete b;
      getch();
      return 0;
    }       


I got the following error :-
C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text+0x24f) In function `main':   [Linker error] undefined reference to `Rect::~Rect()' 
 C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text$_ZN4Rect8instanceEv[Rect::instance()]+0x60) In function `ZN4Rect9area_rectEv':   [Linker error] undefined reference to `Rect::Rect()' 
 C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text$_ZN4Rect8instanceEv[Rect::instance()]+0x60) ld returned 1 exit status .

I know i can make destructor private that Will allow object to be crated only on heap . But in that case how can i delete the created object ? And How can we correct this above error?

Error While creating a class whose object cant be created on stack but only on Heap?
===

I tried writing a code to create a class Whose object can only be created on heap but not 
stack . But During Compilation i got some linking error .The code is :-

      # include<iostream>
      # include<stdio.h>
      # include<conio.h>

      using namespace std;

      class Rect
      { 
       int length;
       int breadth;
       Rect();
   
       public :
       Rect & operator = (const Rect&);       
       Rect(const Rect& abc)
       {
         cout<<"in copy const"<<"\n";        
       }
       ~Rect();
       int area_rect()          
       {return length*breadth;}
   
       void set_value(int a,int b);
          
       static Rect* instance()
       {     
         Rect* ptr=NULL;
         ptr=new Rect ;
         return ptr;
       }
     };

    void Rect::set_value(int a,int b)
    {
      length=a;
      breadth=b;
    }
  
    int main()
    {
     
      Rect* a= Rect::instance();
      a->set_value(10,3);
      cout << "area realted to object a : "  << a->area_rect() <<"\n"; 
      Rect* b=a;    
      b->set_value(10,4);
      cout << "area realted to object a : "  << a->area_rect() <<"\n"; 
      cout << "area realted to object b : "  << b->area_rect() <<"\n"; 
      delete b;
      getch();
      return 0;
    }       


I got the following error :-
C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text+0x24f) In function `main':   [Linker error] undefined reference to `Rect::~Rect()' 
 C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text$_ZN4Rect8instanceEv[Rect::instance()]+0x60) In function `ZN4Rect9area_rectEv':   [Linker error] undefined reference to `Rect::Rect()' 
 C:\Users\Ritesh\AppData\Local\Temp\ccUfbaaa.o(.text$_ZN4Rect8instanceEv[Rect::instance()]+0x60) ld returned 1 exit status .

I know i can make destructor private that Will allow object to be crated only on heap . But in that case how can i delete the created object ? And How can we correct this above error?
