执行另一个类的构造函数时出错
Error in executing the constructor of another class
可能的重复项:
为什么没有调用构造函数?
请看下面的代码
UIHandler.h
#pragma once
class UIHandler
{
public:
UIHandler();
~UIHandler(void);
private:
//Book *books;
};
汉德勒.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)
{
}
主.cpp
#include <iostream>
#include "UIHandler.h"
using namespace std;
int main()
{
UIHandler a();
system("pause");
return 0;
}
在此代码中,我无法在 UIHandler 中执行构造函数,因为代码运行但没有任何反应。如果我将参数传递给 UIHandler 构造函数,它会按预期工作,即使我不使用该构造函数。为什么?请帮忙!
你声明了一个返回UIHandler
类型的函数a
,请参阅最烦人的解析
更新
UIHandler a();
自
UIHandler a;
UIHandler a();
是一个函数声明,它将返回UIHandler
对象。a
后删除()
更新:将定义更改为声明。感谢@JesseGood
相关文章:
- 使用dynamic_cast和构造函数时出错
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 使用根/C++时出错:没有匹配的构造函数来初始化'TTree'
- 使用类的构造函数时出错
- 在 c++ 的构造函数中分配对象向量时出错
- 调用 cv::stereoBM 构造函数时出错
- 尝试从 C++ 中的构造函数从类继承时出错
- 尝试使用构造函数创建对象时出错
- 类中私有结构的构造函数出错
- 在构造函数中分配数组时出错
- 不可复制的对象、映射和shared_ptr:复制构造函数中出错
- 我的类默认构造函数出错
- 在另一个模板类构造函数中使用typdef模板时出错
- C++从构造函数返回值时出错
- 尝试在<int>构造函数中使用 vector 启动类时出错
- 在c++中初始化构造函数中的静态成员变量时出错
- 具有std::原子成员变量的类的复制构造函数/赋值运算符出错
- 使用复制构造函数时出错
- C2057构造函数初始化列表中的常量值定义出错
- 在模板类中使用 r 和 l 值构造函数时出错