【发布时间】:2013-05-07 16:51:46
【问题描述】:
我注意到,即使构造函数没有参数,前者也会进入我制作的构造函数,而后者只有在需要参数时才会进入我制作的构造函数。
赢
// ConsoleApplication11.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
class myRectangle {
int width;
public:
int getWith();
void setWidth(int newWidth) {width = newWidth;};
myRectangle (int);
~myRectangle ();
};
myRectangle::myRectangle (int w) {
width = w;
cout << "myRectangel Constructor\n";
}
myRectangle::~myRectangle() {
cout << "destructor\n";
}
void runObject();
int _tmain(int argc, _TCHAR* argv[])
{
runObject();
int exit; cout << "\n\n";
cin >> exit;
return 0;
}
void runObject()
{
myRectangle mr (5);
}
失败 // ConsoleApplication11.cpp : 定义控制台应用程序的入口点。 //
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
class myRectangle {
int width;
public:
int getWith();
void setWidth(int newWidth) {width = newWidth;};
myRectangle ();
~myRectangle ();
};
myRectangle::myRectangle () {
cout << "myRectangel Constructor\n";
}
myRectangle::~myRectangle() {
cout << "destructor\n";
}
void runObject();
int _tmain(int argc, _TCHAR* argv[])
{
runObject();
int exit; cout << "\n\n";
cin >> exit;
return 0;
}
void runObject()
{
myRectangle mr ();
}
【问题讨论】:
-
你可能想坐下。
MyRectangle mr2();是 function declaration。
标签: c++