2013-03-04 89 views
-2

我工作的C++,下面是我的代碼:cpp程序出現意外錯誤?

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

[C++ Arrays](http://www.tutorialspoint.com/cplusplus/cpp_arrays.htm) – 2013-03-04 06:32:19

回答

2
char[] defaultSurname = "salunke"; 

應該是:

char defaultSurname[] = "salunke"; 

有疑問時使用clockwise spiral rule,它應該幫助。

+0

謝謝你的回答 – BSalunke 2013-03-04 06:33:41

0

[]defaultSurname後:

har defaultSurname[] = "salunke"; 

你的聲明是Java的風格。