函数原型虽然存在,却丢失了
Function prototype missing even though it exists
我对c++不是很有经验,所以如果我犯了一些(很多)愚蠢的错误,我提前道歉。
任务说明如下:在类vector中声明一个双精度类型的动态数组,用于存储对象的元组欧几里得向量,并声明一个整数成员来存储向量的维数。我们应该让用户输入v1和v2的大小和值。然后,我们应该使用v1和v2生成以下格式的输出:
v3 = v1 + v2 = (v1[0]+v2[0] v1[1]+v2[1] .... v1[n]+v2[n])
v3 = v1 - v2 = (v1[0]-v2[0] v1[1]-v2[1] .... v1[n]-v2[n])
v3 = v1 * v2 = (v1[0]*v2[0] + v1[1]*v2[1] + .... + v1[n]*v2[n])
如果v1和v2中的元素个数不相同,或者其中一个为空,则应该产生一个错误消息。
的例子:
如果v1的动态数组有3个元素:
如果v2的动态数组有3个元素:
则输出为:
v3 = v1 + v2 = (3.0 4.5 4.0)
v3 = v1 - v2 = (-1.0 0.5 2.0)
v3 = v1 * v2 = 10
现在,我的问题是,我不断得到"错误:函数"processVector"必须有一个原型",即使函数原型的processVector确实存在。
到目前为止,我得到的如下:
#include<iostream>
class AVector
{
private:
int size;
double* array;
public:
AVector()
{
array = NULL;
}
AVector(int)
{
double input;
size = a;
array = new double[size];
int counter = 0;
while(counter < size)
{
cin >> input;
array[counter] = input;
counter++;
}
}
~AVector()
{
delete[] array;
}
void printArray(int a)
{
cout << "Euclidean vector v" << a << " = (";
for(int i = 0; i < size; i++)
{
cout << array[i] << ' ';
}
cout << ')' << endl;
}
void processVector(AVector a, AVector b)
{
if(a.size != b.size)
{
cout << "Two Euclidean vector should be in the same Euclidean space" << endl;
}
else
{
//...
}
}
};
main.cpp
#include<iostream>
#include "AVector2.h"
using namespace std;
int main()
{
int dimension;
cout << "Input dimension and tuples for a Euclidean vector v1: ";
cin >> dimension;
AVector v1 = AVector(dimension);
v1.printArray(1);
cout << endl;
cout << "Input dimension and tuples for a Euclidean vector v2: ";
cin >> dimension;
AVector v2 = AVector(dimension);
v2.printArray(2);
cout << endl;
processVector(v1, v2);
return 0;
}
如果有人能指出我做错了什么,我将非常感激。
processVector
是AVector
的非静态成员函数。这意味着它必须在像v1.processVector(v2, v3);
这样的AVector
对象上调用。也许你希望它是一个static
成员函数,这样你就可以像这样调用它:
AVector::processVector(v1, v2);
相关文章:
- C++模板来检查友元函数的存在
- 函数向量_指针有不同的原型,我可以构建一个吗
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 功能原型的目的
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- getline() 的原型/库是什么;
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 几个使用相同原型的共享对象导致错误:数据库中已经存在文件
- 指向函数的指针如何指向内存中尚不存在的内容?为什么原型有不同的地址?
- 函数原型虽然存在,却丢失了