Problem with stl list

I made a little program to parse string, but my compiler gives me a mistake. And I don't know what have I done wrong. Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <list>

using namespace std;

class A
{
public:
    list<string> ll;
    A();
    virtual ~A();
};

A::A()
{
    ll = new list<string>;
}

A::~A()
{
    delete ll;
}

int main()
{
    A myList;

    string str = "1+2+3";

    for(int i = 0; i<5; i++)
    {
        if(is digit(str[i]))
        {
            myList.ll.push_back(i); //compiler gives a mistake here
        }
    }

    return 0;
}
C++ is neither C# nor Java. So this syntax

std::list<std::string> ll = new std::list<std::string>;

is invalid in C++.

By the way we are not compilers that to search errors in your code. If your compiler issued an error then post it here.
As I understood my constructor ll = new list<string>; is wrong... Could somebody explain how it should be?
std::list<std::string> ll; //done, list created
When an object of your class is being created then constructors of its members are called. Class std::list has a default constructor that will be called.
Topic archived. No new replies allowed.