我正在研究c ++,以下是我的代码:
test.h
char[] defaultSurname = "salunke";
void in_dev(const char* name, char* surname = defaultSurname );
TEST.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
如何解决此错误?
答案 0 :(得分:2)
char[] defaultSurname = "salunke";
应该是:
char defaultSurname[] = "salunke";
如果有疑问,请使用 clockwise spiral rule ,这应该会有所帮助。
答案 1 :(得分:0)
将[]
放在defaultSurname
之后:
har defaultSurname[] = "salunke";
你声明是Java风格。