开发者

error: expected ')' before '<' token|

开发者 https://www.devze.com 2023-02-02 00:14 出处:网络
I was implementing a String and was giving the definition in .h file. The code in String.h is the following:

I was implementing a String and was giving the definition in .h file. The code in String.h is the following:

#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;
    ch开发者_如何学JAVAar *entries;
};

The error is mentioned in the subject. What is it that I am not following?


You are missing a std:: in front of list<char> :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号