-2

我正在使用 c++,以下是我的代码:

测试.h

char[] defaultSurname  = "salunke";
void in_dev(const char* name, char* surname = defaultSurname );

测试.cpp

#include "test.h"
#include <iostream>
using namespace std;

void in_dev(const char* name, char* surname)
{
    cout <<" surname id "<< surname << endl;
}

int main()
{
  in_dev("Balaji", "Patil");
  return 0;
}

但它给出了以下编译错误:

test.h:1: error: expected unqualified-id before '[' token
test.h:9: error: 'defaultSurname' was not declared in this scope

如何解决此错误?

4

1 回答 1

2
char[] defaultSurname  = "salunke";

应该:

char defaultSurname[]  = "salunke";

如有疑问,请使用顺时针螺旋规则,它应该会有所帮助。

于 2013-03-04T06:30:26.510 回答