怎么运行不了这个c++程序

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:23:08
//:constr1.cpp--constructors& destructors
#include<stdio.h>
class tree
{ int height;
public:
tree(int initialHeight);//constructor
~tree() //destructor
void grow(int years);
void printsize();
};
tree::tree(int initialHeight)
{height=initialHeight;
}
tree::~tree()
{puts("inside tree destructor");
printsize();
}
void tree::grow(int years)
{height+=years;
}
void tree::printsize()
{printf("tree height is %d\n",height);
}
main()
{puts("before opening brace");
{ tree t(12);
puts("after tree creation ");
t.printsize();
t.grow(4);
puts(before closing brace");
}
puts("after closing brace");
}

刚学c++不久,好多简单的问题弄不明白,请大家多多指教,这是《c++编程思想》p56里的一个程序,我在vc++上怎么运行不出来,出现下面问题
-------------------Configuration: 13 - Win32 Debug--------------------<

#include后面少个空格
puts(before closing brace"); 前面少个引号
tree(int initialHeight);//constructor
~tree() 后少个分号

//有两个小错误
#include<stdio.h>
class tree
{ int height;
public:
tree(int initialHeight);//constructor
~tree(); //destructor 这里你原来少分号
void grow(int years);
void printsize();
};
tree::tree(int initialHeight)
{height=initialHeight;
}
tree::~tree()
{puts("inside tree destructor");
printsize();
}
void tree::grow(int years)
{height+=years;
}
void tree::printsize()
{printf("tree height is %d\n",height);
}
main()
{puts("before opening brace");
{ tree t(12);
puts("after tree creation ");
t.printsize();
t.grow(4);
puts("before closing brace"); //这里你原来少半个双引号
}
puts("after closing brace");
}