0

Whenever I use #define T in my code I am getting about 19 errors related to a type_traits file that Xcode uses. I've lowered it to one line in one of my header files. Here is the header file:

#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

If I change the name of T or don't include all of the errors go away. I can't really post the file with the error as it is 1000's of lines long. It's name is "type_traits" and most of the error are something like:

Expected a qualified name after 'typename'

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zeus_masta_funk
  • 1,388
  • 2
  • 11
  • 34
  • You're using a [reserved identifier](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). Anyway, `T` is very often used in templates as a type name. Changing it doesn't work well for any templates using it. – chris Apr 11 '14 at 04:24
  • please avoid `#define` as much as possible. replace them with `const int` or something – Bryan Chen Apr 11 '14 at 05:08
  • Could you elaborate on why I would not want to use #defines? Are you saying to instead globally declare them as const int? – zeus_masta_funk Apr 11 '14 at 14:51

1 Answers1

1

When you use

#define T 0x101 

You replace EVERY single T letter used in the files where your header is included by 0x101

A better solution would be to use an enum instead of a define.

Antzi
  • 12,831
  • 7
  • 48
  • 74