//type.hpp
#pragma once
namespace amxl_lib
{
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef unsigned short wchar;
#define interface class
}
// comparable.hpp
#pragma once
#include "type.hpp"
namespace amxl_lib
{
template <typename T>
interface IComparable
{
public:
virtual int32 compare_to(T* t) = 0;
};
}
// object.hpp
#ifndef _AMXL_LIB_OBJECT_HPP
#define _AMXL_LIB_OBJECT_HPP "amxl_lib::Object"
#include "comparable.hpp"
#ifdef _AMXL_LIB_STRING_HPP
namespace amxl_lib
{
class String;
}
#else
#include "string.hpp"
#endif
namespace amxl_lib
{
class Object : public IComparable<Object>
{
public:
Object()
{
}
virtual uint64 hash_code()
{
return (uint64)this;
}
virtual bool equals(Object* o)
{
return this == o;
}
virtual String* get_name()
{
return new String("Object");
}
int32 compare_to(Object* o) override // IComparable
{
return (this > o ? 1 : (this == o ? 0 : -1));
}
};
}
#endif
// string.hpp
#ifndef _AMXL_LIB_STRING_HPP
#define _AMXL_LIB_STRING_HPP "amxl_lib::String"
#ifdef _AMXL_LIB_OBJECT_HPP
namespace amxl_lib
{
class Object;
}
#else
#include "object.hpp"
#endif
//#include <string.h>
namespace amxl_lib
{
class String : public Object
{
private:
char* m_str;
uint64 m_size;
public:
explicit String()
{
m_size = 0;
m_str = new char[m_size + 1];
m_str[m_size] = '\0';
}
explicit String(uint64 size)
{
m_size = size;
m_str = new char[m_size + 1];
m_str[m_size] = '\0';
}
explicit String(uint64 size, char fill)
{
m_size = size;
m_str = new char[m_size + 1];
m_str[m_size] = '\0';
for (char* p = m_str; *p != '\0'; ++p)
{
*p = fill;
}
}
explicit String(const char* cstr)
{
/*m_size = strlen(cstr);
m_str = new char[m_size + 1];
m_str[m_size] = '\0';
for (uint64 i = 0; i < m_size; ++i)
{
m_str[i] = cstr[i];
}*/
}
const char* cstr()
{
return m_str;
}
uint64 size()
{
return m_size;
}
char char_at(uint64 index)
{
return m_str[index];
}
/*void set(const char* cstr)
{
m_size = strlen(cstr);
m_str = new char[m_size + 1];
m_str[m_size] = '\0';
for (uint64 i = 0; i < m_size; ++i)
{
m_str[i] = cstr[i];
}
}*/
};
}
#endif
// test.cpp
#include <stdio.h>
#include "object"
using namespace amxl_lib;
int main()
{
Object* obj = new Object();
return 0;
}
编译的时候会显示找不到Object,在string.hpp的第20行