Q:

(C++) Passing a vector of objects to a constructor

class A {
public:
   int value;
   A(int value){
       this->value = value;
   }
};

class Relation{
    vector<A> items;

    Relation(vector<A> items){
       this->items = items;
    }
}

int main(){
   vector<A> items;
   items.push_back(A(1));

   Relation r1(items);
}

How do I pass a vector of my new object to a constructor of another object?  In line 13, I get an error "no matching function for call to 'A::A()' "

A:

Like this:
#include <vector>

class A {
public:
    int value;
    A(const int value1 = 0) : value(value1) {}
};

class Relation {
    std::vector<A> items;
public:
    Relation(std::vector<A> items1) : items(items1) {};
    }
};

int main() {
    std::vector<A> items;
    items.push_back(A(1));

    Relation r1(items);
}

Several changes are made to conform to usual C++ practice.  The most important is probably that Relation's contructor is exposed for public use.