【发布时间】:2021-12-18 12:54:33
【问题描述】:
目前我正在尝试创建一个函数来在下面的代码中实现模块化。
[代码 1]
float CBitmapWaterMark::DrawPrintInfoText(HDC hDC)
{
StringFormat* stringFormat = new StringFormat();
// I'm trying to pass a stringFormat object to a member function of a class(CBitmapWaterMark).
stringFormat->SetAlignment(StringAlignmentNear);
stringFormat->SetLineAlignment(StringAlignmentNear);
TestFunction(stringFormat) //help point 1
}
VOID CBitmapWaterMark::TestFunction(StringFormat* stringFormat) // help point 2
{
// implement
}
=> 语法错误标识符 StringFormat
但我不知道如何将它作为函数参数传递以及如何接收它。
在<gdiplusstringformat.h> 中声明的StringFormat 似乎存在问题。
这是一个最小的完整可重现示例:
#include <windows.h>
#include <gdiplus.h>
#include <gdiplusstringformat.h>
StringFormat fmt;
错误日志:
1>C:\Project3 C++\main.cpp(5,17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Project3 C++\main.cpp(5,14): error C2146: syntax error: missing ';' before identifier 'fmt'
【问题讨论】:
-
您的代码并没有特别不同。 StringFormat 是在哪里定义的,你是否包含了必要的标题?
-
@bot
StringFormat不需要定义。编译器抱怨它没有被声明。 -
您的代码看起来不错,但没有声明类(或结构?)
StringFormat,可能是因为您忘记包含声明它的标头。 -
那可能是
Gdiplus::StringFormat。您必须给编译器或我们提供一些线索。 -
它是 Gdiplus::StringFormat 并且包含头文件。