[New(.NET Core)C ++ / CLI项目在定义和实现被拆分时存在编译问题

问题描述 投票:0回答:1

我使用Visual Studio 2019创建了"CLR Empty Project (.Net Core)"项目。

我只是使用“添加类”菜单选项简单地创建了一个新类,它生成了这个类。我在标题中添加了名为Test的函数:


using namespace System;

public ref class Class1 {
    // TODO: Add your methods for this class here.

    void Test();
};

然后使用Visual Studio的generate实现选项,它在.cpp文件中创建了此功能定义:

#include "EngineEditorLayer.h"

#include "pch.h"

void Class1::Test() { throw gcnew System::NotImplementedException(); }

编译时给了我这个错误:

error C2653: 'Class1': is not a class or namespace name

我只能通过将实现移至头文件来解决此错误。

我想念什么吗?是否需要更改设置才能启用.cpp编译?是否有编译器错误阻止我当前执行此操作?

c++-cli visual-studio-2019
1个回答
0
投票

Hans Passant的评论是正确的。必须首先包含pch.h。

很遗憾,我从未收到警告。这是我的输出日志:

1>------ Build started: Project: EngineEditorLayer, Configuration: Debug x64 ------
1>EngineEditorLayer.cpp
1>E:\Other Projects\PixEngine\EngineEditorLayer\EngineEditorLayer.cpp(7,18): error C2653: 'Class1': is not a class or namespace name
1>Done building project "EngineEditorLayer.vcxproj" -- FAILED.
© www.soinside.com 2019 - 2024. All rights reserved.