Complex Complex::operate+(Complex a){Complex m;m.real=a.real+this->rael;}可以不用this吗
时间: 2024-03-27 08:35:23 浏览: 122
可以不用`this`,但是需要将该语句写成以下形式:
```
Complex Complex::operate+(Complex a){
Complex m;
m.real = a.real + real;
m.imag = a.imag + imag;
return m;
}
```
这样做的原因是,当参数和成员变量的名称相同时,需要使用`this`关键字来区分它们。但是,如果你使用不同的名称来表示参数和成员变量,就不需要使用`this`来引用它们了。
相关问题
// 获取表单值 const form = getFieldsValue(); // 条件值的component类型会随着字段的变化发生变化 // 条件值发生变化时获取当前字段列详细数据 const currentFieldData = columnOptions.value.find( (item: Recordable) => item.value === form.field, ) as unknown as Recordable; // 根据字段label const fieldLabel = columnOptions.value.find((item) => item.value === form?.field)?.label; // 判断条件 const conditionType = ARITHMETIC_OPERATOR_BACK.find( (item) => item.value === form?.op, )?.operate; if (form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL) { // 判断条件为空、非空时,清空条件值 conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}; } else { // 字段值和判断条件发生变化 let labelText; // 字段变化 if (key === 'field') { if (currentFieldData?.component !== FormElementEnum.SWITCH) { // 清空条件值 await setFieldsValue({ value: undefined }); labelText = ''; } else { await setFieldsValue({ value: 0 }); labelText = '否'; } } else { // 判断条件和条件值变化 // 当前字段有值集时,component类型为ApiSelect if (currentFieldData?.component === FormElementEnum.API_SELECT) { const fieldVsList = await getVsList(currentFieldData.vsId); labelText = fieldVsList?.find( (item: Recordable) => item.itemValue === form.value, )?.itemText; } else if (currentFieldData?.component === FormElementEnum.SWITCH) { // 当前字段类型为boolean时,component类型为Switch,条件值为开关 labelText = form.value === 1 ? '是' : '否'; } else { // 其他 labelText = form.value; } } conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}${labelText ?? ''}; }简化if语句
可以将 if-else 语句简化为三目运算符,如下所示:
```
conditionName = form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL
? `${fieldLabel ?? ''}${conditionType ?? ''}`
: key === 'field'
? currentFieldData?.component !== FormElementEnum.SWITCH
? (await setFieldsValue({ value: undefined }), '')
: (await setFieldsValue({ value: 0 }), '否')
: currentFieldData?.component === FormElementEnum.API_SELECT
? ((await getVsList(currentFieldData.vsId)), labelText = fieldVsList?.find((item: Recordable) => item.itemValue === form.value)?.itemText)
: currentFieldData?.component === FormElementEnum.SWITCH
? (labelText = form.value === 1 ? '是' : '否')
: (labelText = form.value, '');
```
这样可以减少代码量,使代码更加简洁。
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <tomcat-users xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" version="1.0"> <!-- By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. Built-in Tomcat manager roles: - manager-gui - allows access to the HTML GUI and the status pages - manager-script - allows access to the HTTP API and the status pages - manager-jmx - allows access to the JMX proxy and the status pages - manager-status - allows access to the status pages only The users below are wrapped in a comment and are therefore ignored. If you wish to configure one or more of these users for use with the manager web application, do not forget to remove the <!.. ..> that surrounds them. You will also need to set the passwords to something appropriate. --> <!-- <user username="admin" password="<must-be-changed>" roles="manager-gui"/> <user username="robot" password="<must-be-changed>" roles="manager-script"/> --> <!-- The sample user and role entries below are intended for use with the examples web application. They are wrapped in a comment and thus are ignored when reading this file. If you wish to configure these users for use with the examples web application, do not forget to remove the <!.. ..> that surrounds them. You will also need to set the passwords to something appropriate. --> <!-- <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="<must-be-changed>" roles="tomcat"/> <user username="both" password="<must-be-changed>" roles="tomcat,role1"/> <user username="role1" password="<must-be-changed>" roles="role1"/> --> </tomcat-users> 这个怎么改
你提供的 'tomcat-users.xml' 文件是一个示例文件,其中包含了一些注释和示例用户角色和用户的声明。你需要根据你的需求对其进行修改。
如果你想要使用示例中的某个用户角色和用户,你需要取消相应部分的注释,并设置适当的密码。例如,如果你想要使用示例中的 `admin` 用户作为 `manager-gui` 角色的用户,你可以将以下行的注释取消,并将 `<must-be-changed>` 替换为你自己的密码:
```xml
<!--
<user username="admin" password="<must-be-changed>" roles="manager-gui"/>
-->
```
同时,如果你想要使用其他示例用户角色和用户,你可以按照相同的方式取消注释并设置密码。
如果你想要定义自己的用户角色和用户,你可以按照以下格式添加新的 `<role>` 和 `<user>` 元素:
```xml
<role rolename="your-role-name"/>
<user username="your-username" password="your-password" roles="your-role-name"/>
```
确保将 `<your-role-name>`, `<your-username>`, 和 `<your-password>` 替换为你自己定义的角色名、用户名和密码。
最后,保存并关闭 'tomcat-users.xml' 文件,并重新启动 Tomcat 服务器。这样你就可以使用修改后的用户角色和用户来进行部署和操作了。
阅读全文