具体参数输入
Specific Parameter Input
我对C++相当陌生,所以请原谅我到处都是我的代码,但这是怎么回事,我正在创建一个动态链接库来处理我的游戏资产的解压缩。我非常熟悉无损二进制压缩,但这是正在发生的事情,我需要知道如何让参数是"A 型"或"B 型",仅此而已,我正在使用 Visual Studio,所以我希望自动完成提示告诉我我可以使用"A"或"B"作为参数, 我该怎么做?
cpp
//People where telling me to add code for visual so here
static __declspec(dllexport) char* compress(char* buffer, "8bit Int" | "16bit Int" | "32bit Int", int Value)
{
char* bytes;
//Enter code to convert integer to bytes
strcat_s(bytes, sizeof(bytes) + sizeof(buffer), buffer);
return buffer;
}
像这样?
enum class Integer
{
UNKNOWN = 0,
Bit8 = 1,
Bit16 = 2,
Bit32 = 3,
};
static __declspec(dllexport) char* compress(
char* buffer, Integer intType, int Value)
{
char* bytes;
switch (intType)
{
case Integer::Bit8:
// 8-bits processing.
break;
case Integer::Bit16:
// 16-bits processing.
break;
case Integer::Bit32:
// 32-bits processing.
break;
}
//Enter code to convert integer to bytes
strcat_s(bytes, sizeof(bytes) + sizeof(buffer), buffer);
return buffer;
}
然后你这样称呼它:
compress(buf, Integer::Bit8, 42);
这看起来合适吗?
__declspec(dllexport) enum intType {
_8bit, _16bit, _32bit
};
class COMPRESS
{
public:
char* CreateBuffer(int Size)
{
char* buffer = new char[Size];
return buffer;
}
char* BufferWrite(char* Buffer, intType Type, int Value)
{
char* bytes;
switch (Type)
{
_8bit:
{
bytes = (char*)Value;
}
_16bit:
{
bytes[0] = Value & 0xff;
bytes[1] = (Value >> 8) & 0xff;
}
_32bit:
{
bytes[0] = Value & 0xff;
bytes[1] = (Value >> 8) & 0xff;
bytes[2] = (Value >> 16) & 0xff;
bytes[3] = (Value >> 24) & 0xff;
}
}
strcat_s(Buffer, sizeof(bytes) + sizeof(Buffer), bytes);
return Buffer;
}
相关文章:
- 将输入参数作为右值引用传递?
- 是否可以在命令行中将输入参数传递给可执行文件
- C++基于输入参数的动态代码生成
- 我想知道为什么"std::unique_ptr<int> foo(新 int)"是合法的,因为"std::<int>unique_ptr"要求输入参数类型应该是"int"?
- 如何使用输入参数作为文件的传递?
- 在函数中使用运算符重载,在 c++ 中使用 const 类型输入参数
- 提供变量作为 MATLAB 系统命令的输入参数,以便C++可执行文件
- 函数的函数无法识别输入参数
- 当迭代器(输入参数)通常不是constexpr时,constexpr算法真的有用吗
- 如何将一个使用参数包和typename的类作为函数(c++)的输入参数
- CvMat:输入参数的大小不匹配
- 在什么情况下,使用'const T*'输入参数比'const T&'更可取?
- std::具有两个输入参数的矢量构造函数
- GoogleMock:如何根据另一个输入参数设置ArgReferee?
- 模板化函数以从输入参数推断返回类型 stl-container
- GoogleMock:如何验证输入参数的调用次数?
- 当我将 char 数组发送到输入参数为字符串的函数时会发生什么?
- 应该接受不同输入参数的纯虚函数 - 应该如何实现
- C++主函数的输入参数
- STD :: Atomic_fetch为什么将指针作为其输入参数