如果函数在C++中定义如下:
char *Func() {
return "Text";
}
Run Code Online (Sandbox Code Playgroud)
然后;
Func()[] = 'a';
Run Code Online (Sandbox Code Playgroud)
意味着什么?
这可能意味着面试官想要测试您对面对无效源代码的反应.
我不知道其意图Func()[] = 'a';是什么.C++编译器clang 3.4输出以下内容:
a.cc:3:9: warning: conversion from string literal to 'char *' is deprecated
[-Wc++11-compat-deprecated-writable-strings]
return "Text";
^
a.cc:6:1: error: C++ requires a type specifier for all declarations
Func()[] = 'a';
^~~~
a.cc:6:5: error: function cannot return array type 'int []'
Func()[] = 'a';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
185 次 |
| 最近记录: |