New and delete giving build error

Hi all,
I have written a code which will create object on runtime using new and will destroy it using delete , I want to show that while doing so it calls the constructor and the destructor of the class but I am getting build error for my class
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
  #include<iostream>
#include<new>

using namespace std;

class trynd
{
      int i
      public :
             trynd()
             {
                    cout <<"I am in constructor"<<endl;
             }
             void print()
             {
                  coout << i <<endl;
              }
              ~ trynd()
             {
                    cout <<"I am in destructor"<<endl;
             }
              
};

int main()
{
    {
          trynd * nd = new trynd;
          delete nd;
    }
    system("pause");
    return 0;
}


the error is : [Build Error] [new&delete.o]Error1
What is the problem?
Last edited on
closed account (NUj6URfi)
One error is that line 16 has coout
corrected that and initialized i in constructor too added at line 13 i = 0 but still getting the same error
line 8: missing semicolon.

#include <cstdlib> is missing (needed for system() )
corrected that too and I have used system() always without including cstdlib , it never have error. So may be the problem is somewhere else
Executes correctly for me using Visual Studio after correcting the two errors Chervil pointed out.

Note: It is not necessary to include the <new> header. The new header defines versions of new and delete in the global namespace in addition to the versions in the std namespace.
Topic archived. No new replies allowed.