#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 arrayprivate: int arraySize; float *floatPointer = nullptr;};#endif // DYNAMICARRAY
在我的.cpp文件中,我有以下代码:
#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(){}
float Array::getTings (int index);
和
voID Array::addTings (float itemValue);
有谁知道为什么?我以为我已经正确地将头文件链接到cpp文件,但显然没有?
解决方法 您应该删除cpp文件中的分号.voID Array::addTings (float itemValue);
应该
voID Array::addTings (float itemValue)
正确的代码是:
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{}总结
以上是内存溢出为你收集整理的C,Class:成员错误的外线声明?全部内容,希望文章能够帮你解决C,Class:成员错误的外线声明?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)