如何解决C++警告C4251。

huangapple go评论75阅读模式
英文:

How to solve C++ Warning C4251

问题

You need to modify the MyClassImpl class to have a DLL interface. You can do this by adding the __declspec(dllexport) attribute to the MyClassImpl class, like this:

class __declspec(dllexport) MyClassImpl
{
public:
private:
    const String Name;
};

This will allow MyClassImpl to be used by clients of the MyClass class without triggering the C4251 warning.

英文:

I need to expose MyClass with dllexport. But I have this Warning(C4251).

Code

class MyClassImpl
{
public:
private:
	const String Name;
};

class __declspec(dllexport) MyClass {
public :
private: 
	const MyClassImpl data;
};

Warning

Severity	Code	Description	Project	File	Line	Suppression State
Warning	C4251
'MyClass::data': class 'MyClassImpl' needs to have dll-interface to be used by clients of class 'MyClass'

C/C++ - Command line

/permissive- /ifcOutput "x64\Debug\" /GS /GL /Zc:preprocessor /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "MYTESTLIB_EXPORTS" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /std:c17 /Gd /Oi /MD /std:c++20 /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\MytestLib.pch" /diagnostics:column 

Linker - Command line

/OUT:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "botan.lib" "icudt.lib" "icuin.lib" "icuio.lib" "icutest.lib" "icutu.lib" "icuuc.lib" /IMPLIB:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.lib" /DEBUG /DLL /MACHINE:X64 /OPT:REF /PGD:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"x64\Debug\MyTestLib.dll.intermediate.manifest" /LTCGOUT:"x64\Debug\MyTestLib.iobj" /OPT:ICF /ERRORREPORT:PROMPT /ILK:"x64\Debug\MyTestLib.ilk" /NOLOGO /LIBPATH:"I:\XProjects\MyTestLibWindows\modules\ICU4c-73.1-Windows-x64-Release\lib64" /LIBPATH:"I:\XProjects\MyTestLibWindows\modules\Botan-2.19.3-Windows-x64-Debug\lib" /TLBID:1 

How I have to create a DLL interface?

答案1

得分: 2

这个警告告诉您没有东西可以导出。当您将 __declspec(dllexport) 应用于一个类时,这相当于将 __declspec(dllexport) 应用于该类的每个方法。

您没有声明任何方法。

请参阅Microsoft Learn

英文:

The warning is telling you that there's nothing to export. When you apply __declspec(dllexport) to a class, that is the same as applying __declspec(dllexport) to every method of the class.

You don't have any methods declared.

See Microsoft Learn

huangapple
  • 本文由 发表于 2023年5月7日 03:05:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定