gpt4 book ai didi

c++ - 执行另一个类的构造函数时出错

转载 作者:行者123 更新时间:2023-11-27 23:19:18 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why is there no call to the constructor?

请看下面的代码

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 构造函数,它会按预期工作,即使我没有使用构造函数。这是为什么?请帮忙!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com