可能重复:
为什么没有调用构造函数?
请看下面的代码
UIHandler.h
#pragma once
class UIHandler
{
public:
UIHandler();
~UIHandler(void);
private:
//Book *books;
};
UIHandler.cpp
#include "UIHandler.h"
#include <iostream>
using namespace std;
UIHandler::UIHandler()
{
{
//action once code goes here
}
int selection;
cout << "..............Welcome to DigitalLab Library..........." << endl << endl;;
cout << "Kindly press, " << endl;
cout << "1. Enter Books" << endl;
cout << "2. Display Books"<< endl;
cout << "3. Member Area" << endl;
cout << "Your Selection: ";
cin >> selection;
}
UIHandler::~UIHandler(void)
{
}
主文件
#include <iostream>
#include "UIHandler.h"
using namespace std;
int main()
{
UIHandler a();
system("pause");
return 0;
}
在这段代码中,我无法在 UIHandler 中执行构造函数,因为代码运行但没有任何反应。如果我将参数传递给 UIHandler 构造函数,它应该可以正常工作,即使我没有使用构造函数。这是为什么?请帮忙!