I'm having a tough time creating a an array that holds objects of a class I made. I cannot use std::vector to hold the objects so here is what I tried to do:
This is my cpp file: Resistor.cpp:
#include "Resistor.h"
Resistor::Resistor(int rIndex_, string name_, double resistance_){
int rIndex = rIndex_;
name = name_;
resistance = resistance_;
}
I'm trying to make an array of these Resistor objects in another cpp file: Rparser.cpp:
#include "Resistor.h"
#include "Node.h"
#include "Rparser.h"
Rparser::Rparser(int maxNodes_, int maxResistors_){
maxNodes = maxNodes_;
maxResistors = maxResistors_;
resistorArray = new Resistor[maxResistors_]; //trying to make an array
}
My Rparser.h file looks like this, as you can see I declared a pointer that points to Resistor datatype:
#include "Resistor.h"
#include "Node.h"
class Rparser{
public:
int maxNodes;
int maxResistors;
Resistor *resistorArray; //declared a pointer here
Rparser(int maxNodes_, int maxResistors_);
~Rparser(){};
I'm getting the following errors:
error: no matching function for call to ‘Resistor::Resistor()’
note: candidates are: Resistor::Resistor(int, std::string, double, int*)
note: Resistor::Resistor(const Resistor&)
Why is it treating the line resistorArray = new Resistor[maxResistors]
as a function call instead of creating an array?