0

This is the error I'm getting:

StatisticsProcessor.cpp: In member function ‘void StatisticsProcessor::loadData(std::string)’: StatisticsProcessor.cpp:70:16: error: request for member ‘insert’ in ‘((StatisticsProcessor*)this)->StatisticsProcessor::dataArray’, which is of non-class type ‘Element* {aka int*}’ make: * [StatisticsProcessor.o] Error 1

Here is that part of my code:

if(inStream.is_open()){
    for(int i = 0;;){
        if(!inStream.eof()){
            Element line = 0;
                if(i > 0){
                    inStream >> line;
                    dataArray.insert(line);
                }
                else{
                    dataArray = new(nothrow) Element[line];
                    assert(dataArray != 0);
                }
        }
        else if(inStream.eof()) break;
    }
            // Close file stream
            inStream.close();
}

and here is my insert function:

void StatisticsProcessor::insert(Element e){

    // Increment size
    size++;

    // Add in new value
    dataArray[size-1] = e;
}

Element is just a typedef for int, and dataArray is of type Element*
inStream is an ifstream object, I'm trying to read numbers from a file and insert them into my list class(essentially an array of integers). What am i doing wrong??

1
  • 1
    Show us the declaration of dataArray inside the class.
    – David G
    Sep 22, 2013 at 22:31

1 Answer 1

2

As you've shown us, the insert is a member function of the StatisticsProcessor class. If you want to call that function, the syntax would be:

x.insert(y);

Where x is an object of type StatisticsProcessor and y is an object of type Element (int). Instead, your x is an int* (pointer to int). Pointers don't have a member function named insert, nor any member functions at all, for that matter.

6
  • What would you suggest i do?
    – Riptyde4
    Sep 22, 2013 at 22:32
  • 1
    @Riptyde4: I would suggest you read a C++ book, because to make this mistake is to have a fundamental gap in knowledge on the language. A gap which I cannot possibly fill in this answer. Sep 22, 2013 at 22:33
  • @Riptyde4 Change your array into a std::vector and use push_back.
    – David G
    Sep 22, 2013 at 22:33
  • I'm reading one lol, this is an assignment for a class i'm trying to wrap my head around. I can't use vectors my professor wants us to write our own list class
    – Riptyde4
    Sep 22, 2013 at 22:35
  • @Riptyde4 In that case, change dataArray's type to use your list class instead. Assuming your list interface defines an insert method somewhere.
    – greatwolf
    Sep 22, 2013 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.