Windows 7 cygwin 1.7.20 gcc 4.5.3
我的一个类中有一个方法,enqueue(const PTR X, const void* operation),当尝试调用它时,实际上调用了另一个方法,enqueue(bool X)' 当原始方法更改为, enqueue(const PTR X) 它被正确调用。我不知道我可能做了什么来激起这种行为。代码是可编译的。
/****** SlipDef.h ******/
#ifndef SLIPDEF_H
#define SLIPDEF_H
# include <string>
# include "SlipPointer.h"
using namespace std;
namespace slip {
typedef unsigned char UCHAR;
typedef signed char CHAR;
typedef unsigned short USHORT;
typedef signed short SHORT;
typedef unsigned int UINT;
typedef signed int INT;
typedef unsigned long ULONG;
typedef signed long LONG;
typedef float FLOAT;
typedef double DOUBLE;
typedef SlipPointer * PTR;
typedef SlipPointer * STRING;
} // namespace slip
#endif /* SLIPDEF_H */
/****** SlipHeader.h ******/
#ifndef _SLIPHEADER_H
#define _SLIPHEADER_H
# include <string>
# include "SlipDef.h"
namespace slip {
class SlipHeader {
public:
SlipHeader& enqueue(SlipHeader& X);
SlipHeader& enqueue(bool X);
SlipHeader& enqueue(UCHAR X);
SlipHeader& enqueue(CHAR X);
SlipHeader& enqueue(ULONG X);
SlipHeader& enqueue(LONG X);
SlipHeader& enqueue(DOUBLE X);
SlipHeader& enqueue(const PTR X, const void* operation);
SlipHeader& enqueue(const string& X, bool constFlag = false);
SlipHeader& enqueue(const string* X, bool constFlag = false);
};
};
#endif /* SLIPHEADER_H */
/****** SlipPointer.h ******/
#ifndef SLIPPOINTER_H
#define SLIPPOINTER_H
using namespace std;
namespace slip {
class SlipPointer {
public:
};
} // namespace slip
#endif /* SLIPPOINTER_H */
/****** TheOtherHeader.h ******/
#ifndef _THEOTHERHEADER_H
#define _THEOTHERHEADER_H
# include <string>
# include "SlipDef.h"
namespace slip {
class TheOtherHeader {
public:
TheOtherHeader& enqueue(TheOtherHeader& X);
TheOtherHeader& enqueue(bool X);
TheOtherHeader& enqueue(UCHAR X);
TheOtherHeader& enqueue(CHAR X);
TheOtherHeader& enqueue(ULONG X);
TheOtherHeader& enqueue(LONG X);
TheOtherHeader& enqueue(DOUBLE X);
TheOtherHeader& enqueue(const PTR X);
TheOtherHeader& enqueue(const string& X, bool constFlag = false);
TheOtherHeader& enqueue(const string* X, bool constFlag = false);
};
};
#endif /* _THEOTHERHEADER_H */
/****** main.cpp ******/
# include "SlipHeader.h"
#include "TheOtherHeader.h"
# include <string>
# include <iostream>
using namespace std;
using namespace slip;
int main(int argc, char** argv) {
SlipPointer* ptr = new SlipPointer();
SlipHeader* header = new SlipHeader();
TheOtherHeader* theOtherHeader = new TheOtherHeader();
header->enqueue(ptr);
theOtherHeader->enqueue(ptr);
return 0;
}
/****** SlipHeader.cpp ******/
# include <string>
# include <iostream>
# include "SlipDef.h"
# include "SlipHeader.h"
namespace slip {
static void* ptrOP;
SlipHeader& SlipHeader::enqueue(SlipHeader& X) { cout << "enqueue(SlipHeader& X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(bool X) { cout << "enqueue(bool X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(UCHAR X) { cout << "enqueue(UCHAR X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(CHAR X) { cout << "enqueue(CHAR X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(ULONG X) { cout << "enqueue(ULONG X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(LONG X) { cout << "enqueue(LONG X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(DOUBLE X) { cout << "enqueue(DOUBLE X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(const PTR X, const void* operation = ptrOP) {
cout << "enqueue(PTR X) right answer" << endl; return *new SlipHeader();
};
SlipHeader& SlipHeader::enqueue(const string& X, bool constFlag) { cout << "enqueue(string& X) wrong answer" << endl; return *new SlipHeader();}
SlipHeader& SlipHeader::enqueue(const string* X, bool constFlag) { cout << "enqueue(string* X) wrong answer" << endl; return *new SlipHeader();}
};
/****** TheOtherHeader.cpp ******/
# include <string>
# include <iostream>
# include "SlipDef.h"
# include "TheOtherHeader.h"
namespace slip {
static void* ptrOP;
TheOtherHeader& TheOtherHeader::enqueue(TheOtherHeader& X) { cout << "enqueue(TheOtherHeader& X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(bool X) { cout << "enqueue(bool X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(UCHAR X) { cout << "enqueue(UCHAR X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(CHAR X) { cout << "enqueue(CHAR X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(ULONG X) { cout << "enqueue(ULONG X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(LONG X) { cout << "enqueue(LONG X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(DOUBLE X) { cout << "enqueue(DOUBLE X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(const PTR X) {
cout << "enqueue(PTR X) right answer" << endl; return *new TheOtherHeader();
};
TheOtherHeader& TheOtherHeader::enqueue(const string& X, bool constFlag) { cout << "enqueue(string& X) wrong answer" << endl; return *new TheOtherHeader();}
TheOtherHeader& TheOtherHeader::enqueue(const string* X, bool constFlag) { cout << "enqueue(string* X) wrong answer" << endl; return *new TheOtherHeader();}
};