弦装饰班导致许多构建错误

String decorator class leads to numerous build errors

本文关键字:许多 构建 错误      更新时间:2023-10-16

我已经为std :: string创建了一个装饰器类,该类别(包括在项目中)会导致数千个构建错误源自cmath.h,cstring.h,xstring等文件。.H我无法弄清楚原因。需要字符串操作的项目中的所有文件都使用此类代替STD :: String以保持一致性。

我试图慢慢评论装饰班的某些部分,以试图理解实际发生的事情,但是一旦整个班级被评论出来,这些错误才开始有意义。在这里列出所有错误有太多错误,但是一小部分错误包括:

Error   C2733   'abs': second C linkage of overloaded function not allowed
Error   C2065   'allocator': undeclared identifier
Error   C2974   'std::basic_string': invalid template argument for '_Alloc'
Error   C2873   'strxfrm': symbol cannot be used in a using-declaration
Error   C2535   'void std::basic_string<_Elem,_Traits,_Alloc>::_Construct(_Iter,_Iter)': member function already defined or declared

在多个标准库文件中有成千上万个错误。这是字符串装饰器的标题文件:

#pragma once
#include <string>
#include <vector>
namespace Framework
{
    class String
    {
    private:
        std::string Data;
    public:
        String();
        String(const char*Init);
        String(int Init);
        friend String operator+(String &LHS, String &RHS);  
        friend String operator+(String &LHS, const char *RHS);
        friend String operator+(String &LHS, const char RHS);
        String& operator+=(String &RHS);
        String& operator+=(const char *RHS);
        String& operator+=(const char RHS);
        friend bool operator==(String &LHS, String &RHS);
        friend bool operator==(const String &LHS, const String &RHS);
        friend bool operator==(String &LHS, const char *RHS);
        friend bool operator==(const String &LHS, const char *RHS);
        friend bool operator!=(String &LHS, String &RHS);
        friend bool operator!=(const String &LHS, const String &RHS);
        friend bool operator!=(String &LHS, const char *RHS);
        String& operator=(const char * RHS);
        char operator[](int Index);
        size_t Length();
        size_t IndexOf(String SubString, size_t Offset = 0);
        bool Contains(String SubString, size_t Offset = 0);         
        String SubString(size_t Start, size_t Count = 0);           
        std::vector<String> Split(char Delimeter, bool KeepEmpty = false);
        const char *ToCharString();
        void Insert(int Position, String Text);
        void RemoveAt(int Index);
        int ToInt();
        double ToDouble();          
        bool ToBoolean();
        unsigned __int8 ToByte();
    };      
}

使这一更加困惑的是,该外墙在另一个项目中完美效果,这是在这个新项目中似乎失败的。

我不确定是什么原因造成了这个问题,但是它的分辨率是将字符串。在项目的根源上。一旦我做到了,然后将所有内容都恢复到使用Framework :: string的所有内容,该项目就可以了。

关于为什么工作的线索可能是一个事实,即如果我右键单击#include "String.h"行时,string.h和string.cpp仍在root Directory中并选择打开文档,则打开标准库字符串。h文件而不是我的字符串.h文件。