Reputation:
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct Node1 {
unsigned int vertex;
unsigned int representative;
Node1(unsigned int Vert, unsigned int Rep) : vertex(Vert), representative(Rep) {}
};
class Graph{
vector<Node1> nodes;
public:
void findComponents() {
nodes.emplace_back(1, 1);
nodes.resize(1);
// nodes.resize(newSize);
}
};
int main(){
Graph g;
g.findComponents();
}
I'm getting a ton of weird build errors mainly consisting of "Candidate constructor not viable" and " In instantiation of member function 'std::__1::vector >::resize' requested her"
Upvotes: 0
Views: 1706
Reputation: 26800
To use the below overload of vector::resize()
which you are using in your code, T
must meet the requirements of MoveInsertable and DefaultInsertable.
void resize( size_type count );
DefaultInsertable means that an instance of the type can be default-constructed in-place.
So what you need is a default constructor for Node1
. For that you can do this:
Node1() = default;
Or specify default values for Vert
and Rep
in the existing constructor like this:
Node1(unsigned int Vert = 0, unsigned int Rep = 0) : vertex(Vert), representative(Rep) {}
Upvotes: 3