无法将'char(*)[200]'转换为'char **'

时间:2019-09-29 20:27:45

标签: c++ arrays function compiler-errors

#include <iostream>
#include <string.h>

using namespace std;

void ArrayTimesThree(char*, const char*);

int main()
{
    char s1[200], s2[200], circleword[200];
    cin.getline(s1, 200);
    cin.getline(s2, 200);

    ArrayTimesThree(circleword, s1);
    cout<<circleword[1];
}

void ArrayTimesThree(char *dest[], char *source[])
{
    *dest[0] = NULL;
    strcat(*dest, *source);
    strcat(*dest, *source);
    strcat(*dest, *source);
}
  

main.cpp | 21 |错误:无法将参数'1'的'char(*)[200]'转换为'char **'到'void ArrayTimesThree(char **,char **)'

2 个答案:

答案 0 :(得分:2)

您正在将ArrayTimesThree传递给char *,但是,在方法签名中,您告诉它期望有char **。不要忘记,使用ON CREATE FOREACH(ignoreme in case when event.article is not null then [1] else [] end |... multiple statements运算符会被视为取消引用。试试这个:

[]

免责声明:我不确定这段代码对您的期望是什么,因此我不能保证逻辑正确。但是,这将解决您的编译器错误,并且似乎可以正确编写代码。

答案 1 :(得分:1)

问题实际上仅仅是因为您的ArrayTimesThree的初始 声明 (是“正确的”)与 <您稍后给出的em> definition (实际上是错误的)。如下更改您的定义,它会起作用:

void ArrayTimesThree(char* dest, const char* source) // Needs to be the same as in the previous declaration!
{
    dest[0] = '\0';   // Don't assign a string pointer to NULL! Instead, set its first character to the nul character
//  strcpy(dest, ""); // ALternatively, use strcpy with an empty string to clear "dest"
    strcat(dest, source); // strcat takes char* and const char* arguments ...
    strcat(dest, source); // ... so there is no need to 'deference the values ...
    strcat(dest, source); // ... now that the argument types have been 'corrected'
}

顺便说一句,我注意到s2函数中main的输入值从未真正使用过……这是您现在想要的吗?

相关问题