Hello, I made a class and now I want to store instances of those classes in an array. I looked it up and found it was as easy as:

className arrayName[x]

When I tried that I got this error:
error: no matching function for call to 'archerTower::archerTower()'|

My class:

// class
class archerTower{
    float cX;
    float cY;
    float radius;
    public:
        archerTower(float,float,float);
        float getcX(){return cX;}
        float getcY(){return cY;}
        float getRadius(){return radius;}
};

//constructor
archerTower::archerTower(float x, float y, float r)
{
    cX = x;
    cY = y;
    radius = r;
}

And finally when I try to create the array:

archerTower archerTowerArray[4];

Can anyone please help me?

Recommended Answers

All 2 Replies

To create an array of objects without initialization, the object type must have a default constructor. The rule in C++ is that a default constructor is generated for you if you don't explicitly define any constructor explicitly. Your class has a three parameter constructor, so no default constructor is generated automatically. You need to do it explicitly.

Thank You!! It worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.