Arrays of Pointers

#include<iostream>
using namespace std;
const int size = 3;
class AAAA
{
private:
int item;
AAAA* next;
public:
AAAA(int,AAAA*);
};
int main()
{

AAAA* a = new AAAA[size]={0,NULL};//my problem is no matching function
Hi.
How can I create A Constructor for initialize a object.

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
#include<iostream>
using namespace std;

const int size = 3;

class AAAA
{
private:

    int item;
    AAAA * next;

public:

    AAAA():item(0),next(0){}
};

int main()
{

    AAAA * a = new AAAA[size];

    //...

    delete[] a;
    return 0;
}
Arrays are effectively obsolete in most modern C++ code, you might consider using a vector instead, which is a dynamically resizable array.

1
2
3
4
5
6
7
8
9
10
11
12
#include <vector>

class AAAA
{
    // etc.
};

int main()
{
    int size = 3;
    std::vector<AAAA> a(size);
} 
the size of a vector may be specified when you create it, or you can change its size later on; You also do not need to worry about delete, nor do you need to fret over memory leaks; best of all, vectors are easier to use and to learn about than "raw" arrays.

http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/
Last edited on
Although this is irrelevant to what the OP asked, I'll play along.

This site also has a reference -> http://cplusplus.com/reference/stl/vector/
Topic archived. No new replies allowed.