//
// Media.h define the class cell
//
#ifndef MEDIA_H
#define MEDIA_H
#include<vector>
#include<string>
using namespace std;
class Media
{
private:
// media name
string name;
// the density vector
vector<double> density;
// the capacity vector
vector<double> cp;
// the thermal conductivity vector
vector<double> thermalConductivity;
// the viscorsity vector
vector<double> viscorsity;
public:
// default constructor initilized with name and mesh*
Media(){ }
~Media(){}
void reSizeAll(const int& size)
{
density.resize(size);
cp.resize(size);
thermalConductivity.resize(size);
viscorsity.resize(size);
}
// set density vector with a constant value
void setDensity(const double & aVal)
{
vector<double>::iterator it;
for( it=density.begin(); it!=density.end(); it++ ) *it=aVal;
}
// get the density vector
vector<double>& getDensity() const {return density;}
};// end of the class defination
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
#endif
I want to return the vector by reference in the function getDensity. but the vs2008 gives me the following error:
1>g:\computation\c++cfd\flowingheat\flowingheat\media.h(58) : error C2440: 'return' : cannot convert from 'const std::vector<_Ty>' to 'std::vector<_Ty> &'
I have not declare the vector density as const vector density, what is the reason for this problem.
also in the getDensity(), i have not change the vector,i think declar getDensity() as getDensity() const is correct.