简体   繁体   English

使用 C++ 控制台应用程序中内置的类的 MFC 编译错误

[英]MFC compile error using classes built in C++ console app

I am trying to build a fractal application in MFC using code that I have written in a C++ console application.我正在尝试使用我在 C++ 控制台应用程序中编写的代码在 MFC 中构建一个分形应用程序。 I have a created all the same classes in the MFC application and I clicked build (I wasn't expecting it to work)我在 MFC 应用程序中创建了所有相同的类,然后单击了构建(我没想到它会起作用)

Anyway it complains a lot about the RGB.h class and the RGB.cpp class.无论如何,它对 RGB.h 类和 RGB.cpp 类抱怨很多。
Do I need to change something in the configuration of the project?我需要更改项目配置中的某些内容吗?

If I build the console application it works fine, but clearly there are differences when trying to use the classes in an MFC application.如果我构建控制台应用程序它工作正常,但显然在尝试使用 MFC 应用程序中的类时存在差异。

Just wanted to know if there is anything I can do about these two errors as I'm not sure where to start with them.只是想知道我是否可以对这两个错误做些什么,因为我不确定从哪里开始。

RGB.cpp RGB.cpp

compiler error: expected a ;编译器错误:应为 ;

RGB::RGB(double r, double g, double b) : r(r), g(g), b(b) {}

RGB.h RGB.h

Error C2143 syntax error: missing ')' before '|'错误 C2143 语法错误:在“|”之前缺少“)”

RGB(double r, double g, double b);

There is no issue with the code posted as such.这样发布的代码没有问题。 But RGB is a macro, declared in wingdi.h, that gets pulled in when including Windows.h.但是RGB是一个宏,在 wingdi.h 中声明,在包含 Windows.h 时会被引入。 It is defined like this:它是这样定义的:

#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))

This preprocessor macro clashes with the symbol used for the type.此预处理器宏与用于该类型的符号发生冲突。 It's easiest to use a different symbol for the type, eg rgb .最容易为类型使用不同的符号,例如rgb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM