Trouble with constructor for a class

Hi there, I'm having a little trouble getting a constructor going. I can define the class OK and
initialize objects using the function "setVals(...)" (see code below), but I would like to make
a constructor for the class, and I keep getting a compiler error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <vector>

using namespace std;

class xyDat {
	vector< vector<double> > dat;
  public:
  	void setVals(vector< vector<double> >);
};

xyDat::xyDat (vector< vector<double> >  myDat){
	dat=myDat;
}

void xyDat::setVals(vector< vector<double> > datToSet){
	dat = datToSet;
}


int main(){
	return 0;
}


I'm compiling with g++, and the error given is:

1
2
3
constructorError.cpp:11: error: prototype for ‘xyDat::xyDat(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >)’ does not match any in class ‘xyDat’
constructorError.cpp:5: error: candidates are: xyDat::xyDat(const xyDat&)
constructorError.cpp:5: error:                 xyDat::xyDat()


Apologies if this is just a dumb syntax problem, or something. I can't seem to see it, if it is.
Last edited on
You did not declare the constructor in the class.

Write

1
2
3
4
5
6
class xyDat {
	vector< vector<double> > dat;
  public:
  	xyDat (vector< vector<double> >  myDat);
  	void setVals(vector< vector<double> >);
};
Last edited on
That did the trick. Thanks. For some reason I assumed the constructor was immune to this requirement, and that was just dumb.
Topic archived. No new replies allowed.