C ++, Class: Out of order element error declaration?

I am trying to create a dynamic array using the class. In my header file, I have the following code:

#ifndef DYNAMICARRAY
#define DYNAMICARRAY
#include <iostream>

class Array 
{

public:

    Array(); // Constructor - Initialises the data members
    ~Array(); // Destructor - That deletes the memory allocated to the array
    void addTings (float itemValue); // which adds new items to the end of the array
    float getTings (int index); // which returns the item at the index
    void size(); // which returns the number of items currently in the array

private:

    int arraySize;
    float  *floatPointer = nullptr;
};

#endif // DYNAMICARRAY

      

And in my .cpp file I have the following code:

#include "DYNAMICARRAY.h"

Array::Array()
{
    floatPointer = new float[arraySize];
}

Array::~Array()
{
    delete[] floatPointer;
}

void Array::addTings (float itemValue);  // Out-of-line declaration ERROR
{
    std::cout << "How many items do you want to add to the array";
    std::cin >> arraySize;
}

float Array::getTings (int index);    // Out-of-line declaration ERROR
{

}

void Array::size()
{

}

      

I get the message Out-of-line member, there must be a compile-time definition error on both lines:

float Array::getTings (int index);

      

and

void Array::addTings (float itemValue);

      

Can anyone understand why? I thought I linked the header file to the cpp file correctly, but obviously not?

+3


source to share


2 answers


You have to remove semicolons in your cpp file.

void Array::addTings (float itemValue);

      

it should be



void Array::addTings (float itemValue)

      

Correct code:

void Array::addTings (float itemValue)  // Out-of-line declaration ERROR
{
std::cout << "How many items do you want to add to the array";
std::cin >> arraySize;


}

float Array::getTings (int index)    // Out-of-line declaration ERROR
{

}

      

+10


source


Get rid of semi-columns in the definition of functions. See below



void Array::addTings (float itemValue);
{
}
float Array::getTings (int index);
{
}

void Array::addTings (float itemValue)
{
}
float Array::getTings (int index)
{
}

      

0


source







All Articles