草庐IT

carriage-return

全部标签

c++ - 对于不返回 void 的 C++ 函数,是否必须使用 return 语句?

我的HerbSchildt关于C++的书说:“......在C++中,如果一个函数被声明为返回一个值,它必须返回一个值。”但是,如果我编写了一个具有非void返回类型的函数并且不返回任何内容,编译器会发出警告而不是错误:“控制到达非void函数的结尾。”我使用gcc(MinGW)并设置了-pedantic标志。 最佳答案 §6.6.3/2:Flowingofftheendofafunctionisequivalenttoareturnwithnovalue;thisresultsinundefinedbehaviorinavalue

c++ - 对于不返回 void 的 C++ 函数,是否必须使用 return 语句?

我的HerbSchildt关于C++的书说:“......在C++中,如果一个函数被声明为返回一个值,它必须返回一个值。”但是,如果我编写了一个具有非void返回类型的函数并且不返回任何内容,编译器会发出警告而不是错误:“控制到达非void函数的结尾。”我使用gcc(MinGW)并设置了-pedantic标志。 最佳答案 §6.6.3/2:Flowingofftheendofafunctionisequivalenttoareturnwithnovalue;thisresultsinundefinedbehaviorinavalue

c++ - 我不明白为什么这个函数 "returns a pointer from the list"

我正在读的书,IntroductiontoDataStructureswithLinkedLists(Presentation21),有2个链表示例。这是第一个:EnemySpaceShip*getNewEnemy(){EnemySpaceShip*p_ship=newEnemySpaceShip;p_ship->x_coordinate=0;p_ship->y_coordinate=0;p_ship->weapon_power=20;p_ship->p_next_enemy=p_enemies;p_enemies=p_ship;returnp_ship;}链表的第二个例子是这个:En

c++ - 我不明白为什么这个函数 "returns a pointer from the list"

我正在读的书,IntroductiontoDataStructureswithLinkedLists(Presentation21),有2个链表示例。这是第一个:EnemySpaceShip*getNewEnemy(){EnemySpaceShip*p_ship=newEnemySpaceShip;p_ship->x_coordinate=0;p_ship->y_coordinate=0;p_ship->weapon_power=20;p_ship->p_next_enemy=p_enemies;p_enemies=p_ship;returnp_ship;}链表的第二个例子是这个:En

javascript - GraphQL "Cannot return null for non-nullable"

这个问题在这里已经有了答案:WhydoesaGraphQLqueryreturnnull?(6个回答)关闭3年前。尝试制作我的第一个graphQL服务器,这是我目前所写的。https://gist.github.com/tharakabimal/7f2947e805e69f67af2b633268db0406当我尝试按用户名过滤用户时,GraphQL上会弹出以下错误。ErroronGraphQL错误发生在UserQueriesQL.js中的用户字段中。我在解析函数上传递参数的方式有什么问题吗?user:{type:UserType,args:{username:{name:'usern

javascript - GraphQL "Cannot return null for non-nullable"

这个问题在这里已经有了答案:WhydoesaGraphQLqueryreturnnull?(6个回答)关闭3年前。尝试制作我的第一个graphQL服务器,这是我目前所写的。https://gist.github.com/tharakabimal/7f2947e805e69f67af2b633268db0406当我尝试按用户名过滤用户时,GraphQL上会弹出以下错误。ErroronGraphQL错误发生在UserQueriesQL.js中的用户字段中。我在解析函数上传递参数的方式有什么问题吗?user:{type:UserType,args:{username:{name:'usern

javascript - 使用 'return' 创建对象时使用 'new'

我今天发现了一件很奇怪的事情:如果您使用构造函数和new关键字创建对象,但return从构造函数中返回一个函数,它的行为如下:新创建的“对象”是一个函数。这个新函数可以像平常一样被调用,但是......如果您在构造函数中维护对this的引用,则this将引用从构造函数正确创建的对象。这是您期望从new返回的内容。这是一个例子:functionConstructor(){varself=this;this.name='instance';returnfunction(){returnself;}}所以如果你像这样实例化它:varinstance=newConstructor()结果如下:

javascript - 使用 'return' 创建对象时使用 'new'

我今天发现了一件很奇怪的事情:如果您使用构造函数和new关键字创建对象,但return从构造函数中返回一个函数,它的行为如下:新创建的“对象”是一个函数。这个新函数可以像平常一样被调用,但是......如果您在构造函数中维护对this的引用,则this将引用从构造函数正确创建的对象。这是您期望从new返回的内容。这是一个例子:functionConstructor(){varself=this;this.name='instance';returnfunction(){returnself;}}所以如果你像这样实例化它:varinstance=newConstructor()结果如下:

javascript - 为什么我需要在 node.js 中写 "function(value) {return my_function(value);}"作为回调?

对JS完全陌生,所以如果这是令人难以置信的明显,请原谅。假设我想使用映射字符串的函数f过滤字符串列表->bool。这有效:filteredList=list.filter(function(x){returnf(x);})这失败了:filteredList=list.filter(f)为什么???代码示例:~/projects/node(master)$node>varitems=["node.js","file.txt"]undefined>varregex=newRegExp('\\.js$')undefined>items.filter(regex.test)TypeError:

javascript - 为什么我需要在 node.js 中写 "function(value) {return my_function(value);}"作为回调?

对JS完全陌生,所以如果这是令人难以置信的明显,请原谅。假设我想使用映射字符串的函数f过滤字符串列表->bool。这有效:filteredList=list.filter(function(x){returnf(x);})这失败了:filteredList=list.filter(f)为什么???代码示例:~/projects/node(master)$node>varitems=["node.js","file.txt"]undefined>varregex=newRegExp('\\.js$')undefined>items.filter(regex.test)TypeError: