C,Class:成员错误的外线声明?

C,Class:成员错误的外线声明?,第1张

概述我正在尝试使用类创建动态数组.在我的头文件中,我有以下代码: #ifndef DYNAMICARRAY#define DYNAMICARRAY#include <iostream>class Array {public: Array(); // Constructor - Initialises the data members ~Array(); // Destr 我正在尝试使用类创建动态数组.在我的头文件中,我有以下代码:

#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:成员错误的外线声明?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1218212.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存