错误:预期')'在'<'之前令牌|

时间:2010-12-30 13:54:49

标签: c++

我正在实现一个String并在.h文件中给出定义。 String.h中的代码如下:

#include<list>
class String
{
    public:
    String();//Constructor
    String(char * copy);//For converting CString to String
    const char *c_str(const String &copy);//For converting String to Cstring
    String(list<char> &copy);//Copying chars from list
    //Safety members
    ~String();
    String(const String &copy);
    void operator = (const String &copy);
    protected:
    int length;
    char *entries;
};

主题中提到了错误。我不跟踪的是什么?

2 个答案:

答案 0 :(得分:7)

您在std::前面缺少list<char>

String(std::list<char> &copy);

答案 1 :(得分:1)

一次解决了几个问题:

#include <list>

class String
{
public:
 String();
 String(const String &c);
 String(const char * c);
 String(std::list<char> c); // No idea why someone would have this constructor, but it was included in the original ...
 ~String();

 String& operator = (const String &c);

 const char *c_str();
private:
 unsigned int length;
 char* entries;
};