【发布时间】:2014-04-11 04:20:50
【问题描述】:
每当我在我的代码中使用 #define T 时,我都会收到大约 19 个与 Xcode 使用的 type_traits 文件相关的错误。我已将其降低到我的一个头文件中的一行。这是头文件:
#ifndef __SlidingWindowCompression__Utils__
#define __SlidingWindowCompression__Utils__
// DEFINITIONS:
#define CONT_FLAG 0x00
#define STOP_FLAG 0xFF
#define BYTE_SIZE 8
#define A_KEY 0x000
#define T_KEY 0x001
#define G_KEY 0x010
#define C_KEY 0x100
#define N_KEY 0x011
#define A 0x100
#define T 0x101 //ERROR RIGHT HERE WHEN INCLUDED!!!
#define G 0x110
#define C 0x111
// INCLUDES:
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
// FUNCTION DECLERATIONS:
std::string getKey(std::ifstream& inStream);
int getReadSize(std::ifstream& inStream);
void outputHeader(const int READ_SIZE, const std::string& KEY, std::ofstream& outStream);
bool setRead(std::string& read, std::ifstream& inStream);
void stuffit(unsigned char value, int bits, int endFlag, std::ofstream& outStream);
void setIndexAndBitset(const std::string& KEY, std::string& read, uint16_t& index, std::vector<int>& bits);
unsigned char getHex(const char readChar, const char keyChar);
#endif
如果我更改 T 的名称或不包含所有错误,则消失。我不能真正发布带有错误的文件,因为它有 1000 行长。它的名字是“type_traits”,大部分错误是这样的:
在 'typename' 之后需要一个限定名称
【问题讨论】:
-
您使用的是reserved identifier。无论如何,
T经常在模板中用作类型名称。更改它不适用于任何使用它的模板。 -
请尽量避免
#define。将它们替换为const int或其他东西 -
您能否详细说明为什么我不想使用#defines?您是说改为将它们全局声明为 const int?
标签: c++ xcode c-preprocessor