c++ - 为什么我会收到创建基础类(class)的警告?

标签 c++

<分区>

我创建了这个,但我收到链接错误,但我不知道为什么...

系统信息.h

#include <iostream>

class SysInfo 
{

  public:
    SysInfo();
    ~SysInfo();

  private:

};

系统信息.cpp

#include "SysInfo.h"

using namespace std;

SysInfo::SysInfo()
{
  cout << "Object is being created" << endl;
} 

SysInfo::~SysInfo()
{
  cout << "Object is being deleted" << endl;
}

主要

#include <tchar.h>
#include "Sysinfo.h" 

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    SysInfo inf;
    getchar();

    return 0;
}

留言

warning C4930: 'SysInfo inf(void)': prototyped function not called (was a variable definition intended?)

问题已解决。您看到的代码是更正后的代码。我改了#include <SysInfo.h>#include "SysInfo.h"并关闭 visual studio 2012 中的预编译设置。这也会导致错误。

最佳答案

SysInfo inf();是函数声明 inf , 返回 SysInfo类(class)。

应该是SysInfo inf;

#include <SysInfo.h>也是一个可能的担忧来源。参见 this获取更多信息。

关于c++ - 为什么我会收到创建基础类(class)的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43675217/

相关文章:

c++ - CoreBluetooth 与 C++

c++ - 模板中的 `class =` 是什么意思?

c++ - QuickSort 不排序数组

c++ - 为什么 RVO 不会在这里发生?

c++ - 为什么 std::enable_shared_from_this 允许多个 std::shared_ptr 实例?

c++ - 递归搜索计算机中的文件

c++ - 找到上信封的最大长度

c++ - 我的 is_complete 类型特征的实现是否暴露了编译器错误?

c++ - 如何在 Unix TeamCity 构建代理上设置环境变量 PATH 和 LD_LIBRARY_PATH?

c++ - 如何将 winhttp api 与 "transfer-encoding: chunked"一起使用