简体   繁体   English

错误:“ <”令牌|之前的预期“)”

[英]error: expected ')' before '<' token|

I was implementing a String and was giving the definition in .h file. 我正在实现一个String,并在.h文件中给出了定义。 The code in String.h is the following: 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;
};

The error is mentioned in the subject. 该主题中提到了错误。 What is it that I am not following? 我没有关注什么?

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

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

Fixed several of your issues at once: 一次修复了您的几个问题:

#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;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM