Setting Class Variables to Arguments of a Member Function

Hi Everyone,

I'm trying to create a member of a class to pass data for that class to use. The following is the code for the specific member that sets the data:
1
2
3
4
5
6
7
8
9
void plotter::setData(QVector<double> xdata, QVector<double> ydata){
    this->xData = xdata;
    this->yData = ydata;
    arraySize = xData.size();
    cout << "    ________________   " << endl;
    cout << "   |                   " << endl;
    cout << "   |   SET DATA        " << endl;
    cout << "   |________________   " << endl;
}


I know it's bad practice to set variables like I did with xData and xdata, but the program errors out here with code -1073741819 (I believe a memory reference location error) and I have no idea why. It appears to have a problem with this->xData = xdata;, as well as the next line. xData, yData, and arraySize are all private variables of the plotter class as is prototyped in the header file below.

1
2
3
4
5
6
7
8
9
10
class plotter{
public:
    void setData(QVector<double> xdata, QVector<double> ydata);
    string getData();
    void plotData();
private:
    QVector<double> xData;
    QVector<double> yData;
    int arraySize;
};


I am hopelessly confused; I really appreciate any insight into this. Thank you.
setData is a member function of the class so it already has access to xData and yData.
It's like trying this:
1
2
3
4
5
main()
{
int variable;
this->variable = 5; //would u use 'this' here?
}
I do not see any problem in the code of setData except that I do not understand the meaning of data member arraSize. Why do you can not use xData.size() directly? Also what is the type of xData.size()? I doubt that its type is int.
soranz:
I see what you are saying. Unfortunately though, either way I run the program (including and not including this->), I receive the same output:
The program has unexpectedly finished.
C:\Users\Ownerer\Documents\QtProjects\qtprog\debug\qtprog.exe exited with code -1073741819


vlad from moscow:
arraySize is there only for recognition purposes - I only define it because I will remember it better than xData.size().

QVector's size member is of the type int. http://doc.qt.nokia.com/4.7-snapshot/qvector.html#size
Topic archived. No new replies allowed.