请查看以下代码
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)
{
}
Main.cpp的
#include <iostream>
#include "UIHandler.h"
using namespace std;
int main()
{
UIHandler a();
system("pause");
return 0;
}
在这段代码中,我无法在UIHandler中执行构造函数,因为代码运行但没有任何反应。如果我将参数传递给UIHandler构造函数,它应该工作,即使我不使用构造函数。这是为什么?请帮忙!
答案 0 :(得分:3)
答案 1 :(得分:1)
UIHandler a();
是一个函数声明,它将返回UIHandler
个对象。在()
a
更新:将定义更改为声明。感谢@JesseGood