【问题标题】:Problem passing parameters into main function in C++ test bench在 C++ 测试台中将参数传递给主函数的问题
【发布时间】:2019-07-30 20:45:11
【问题描述】:

我正在尝试使用测试台测试我在 C++ 中创建的函数。主要函数参数为两个8x8数组:

 void multiplyArray2(int A[8][8], int B[8][8]){

在我的测试台文件中,我创建了一个值的输入数组和一个输出数组,并尝试将它们输入到函数中:

int dataIn[8][8];
int dataOut[8][8];

int main(){

    dataIn = {{68, 68, 67, 67, 66, 67, 67, 67},
                {69, 69, 68, 68, 67, 69, 67, 67},
                {70, 70, 71, 71, 70, 70, 70, 70},
                {72, 72, 72, 71, 72, 72, 72, 71},
                {74, 74, 73, 73, 74, 74, 74, 74},
                {75, 76, 75, 75, 76, 76, 75, 75},
                {76, 77, 77, 76, 76, 76, 76, 76},
                {79, 78, 79, 79, 78, 76, 77, 77}};


    multiplyArray2(dataIn, dataOut);

当我尝试将参数输入到测试台中的函数中时,它会向我提供以下错误消息:

我也不知道为什么……

【问题讨论】:

  • 您可能想研究如何将“数组”传递给函数,或者考虑使用更好的数据类型,例如 std::array。此外,您缺少一些右括号,并且在函数之前初始化时出现了不同的错误。一旦我解决了这个问题,函数声明就很好了,但容易出错,因为函数不知道维度。

标签: c++ arrays parameters http-live-streaming test-bench


【解决方案1】:
void multiplyArray2(int A[][8], int B[][8])

这应该可以解决您的问题。

在 C 和 C++ 中默认情况下不太支持多维数组。只有在编译时知道N-1 dimensions 时,才能传递N-dimension 数组。

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 2011-08-19
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 2015-03-14
    • 1970-01-01
    相关资源
    最近更新 更多