函数原型虽然存在,却丢失了

Function prototype missing even though it exists

本文关键字:存在 原型 函数      更新时间:2023-10-16

我对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;
}
如果有人能指出我做错了什么,我将非常感激。

processVectorAVector的非静态成员函数。这意味着它必须在像v1.processVector(v2, v3);这样的AVector对象上调用。也许你希望它是一个static成员函数,这样你就可以像这样调用它:

AVector::processVector(v1, v2);