问题列表 - 第317987页

结构体或类的实例可以被视为变量吗?

我读了:

\n
    \n
  • 变量是内存位置的名称。
  • \n
  • 在 C++ 中,变量实际上只是保留给程序\xe2\x80\x99 使用的一点内存。\n( https://en.cppreference.com/book/intro/variables )
  • \n
  • 变量名是标识符。标识符是 C++ 中用于各种事物的标签,包括函数、类、命名空间以及变量。
  • \n
\n

(意味着变量名只是标识符的一种情况)

\n

在标准 C++ 术语中,我们可以将结构体或类的实例名称视为变量吗?或者我们应该只称其为“标识符”吗?

\n

我知道这绝对是一个菜鸟问题,但即使我尝试从多个来源读取变量的定义,我自己也确实无法回答这个问题。请帮忙。

\n

c++ variables

2
推荐指数
1
解决办法
188
查看次数

如何验证是否在“move”闭包中调用了clone()?

我是 Rust 新手,我想验证是否clone()需要关闭move。

我定义了一种类型Test并实现了该Clone特征:

struct Test {
    b : bool,
}

impl Clone for Test {
    fn clone(&self) -> Self {
        println!("clone called");
        *self
    }
    
}

impl Copy for Test {
    
}
Run Code Online (Sandbox Code Playgroud)

然后我在move闭包中使用它:

    let test = Test{b:true};

    println!("Memory address of test: {:?}", std::ptr::addr_of!(test.b));

    let c = move || { println!("Memory address of test: {:?}", std::ptr::addr_of!(test.b)); };
    c();    // <--- does clone() be called here?

    println!("Memory address of test: {:?}", std::ptr::addr_of!(test.b)); …
Run Code Online (Sandbox Code Playgroud)

rust

0
推荐指数
1
解决办法
67
查看次数

VSCode 工作区设置自行更改

我在 React 项目中使用 eslint、prettier、vite。

我已将 VSCode 工作区设置设置为"source.fixAll.eslint"和。但它不断更改为自动,例如当我打开 VSCode 或当我编码时。"source.organizeImports"true"explicit"

可能是什么原因?

// .vscode/settings.json (workspace settings)

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true, // keeps automatically changing to "explicit"
    "source.organizeImports": true // keeps automatically changing to "explicit"
  },
  "editor.formatOnSave": true,
  "editor.wordWrap": "on",
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}
Run Code Online (Sandbox Code Playgroud)
// package.json devDependencies

"devDependencies": {
  "@testing-library/react": "^14.0.0",
  "@types/jest": "^29.5.6",
  "@types/react": "^18.2.15",
  "@types/react-dom": "^18.2.7",
  "@typescript-eslint/eslint-plugin": "^6.0.0",
  "@typescript-eslint/parser": "^6.0.0",
  "@vitejs/plugin-react": "^4.0.3",
  "eslint": "^8.45.0",
  "eslint-plugin-prettier": "^5.0.1",
  "eslint-plugin-react": "^7.33.2",
  "eslint-plugin-react-hooks": "^4.6.0",
  "eslint-plugin-react-refresh": "^0.4.3",
  "husky": "^8.0.3",
  "jest": "^29.7.0",
  "jest-environment-jsdom": …
Run Code Online (Sandbox Code Playgroud)

visual-studio-code eslintrc

59
推荐指数
1
解决办法
1万
查看次数

Bitbucket管道错误

在我的管道中出现以下错误。谁可以帮我这个事 ?我正在尝试通过 bitbucket 管道部署我的 ecs 服务,但遇到此错误。我尝试更新 docker、pip、docker-compose 所有内容,但没有成功

当前版本: docker-compose:1.29.2 pip:23.3.1 docker:最新

我的 yaml 文件代码:

          name: "Deployment"
          services:
            - docker
          caches:
            - node
            - docker
          script:
            - pip install awscli docker-compose
            - docker-compose --version
            - aws configure set aws_access_key "${AWS_ACCESS_KEY}"
            - aws configure set aws_secret_key "${AWS_SECRET_KEY}"
            - docker-compose -f ./docker/docker-compose.stg.yml build
            - eval $(aws ecr get-login --no-include-email --region us-east-1 | sed 's;https://;;g')
            - docker push ${DOCKER_REGISTRY}/dashboard-service:stg
            - aws ecs update-service --cluster new-services --service dashboard-service --force-new-deployment```

**ERROR CODE:**
+ docker-compose …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose bitbucket-pipelines cicd

6
推荐指数
1
解决办法
1578
查看次数

Rust 应用程序退出并显示错误代码:(退出代码:0xc0000005,STATUS_ACCESS_VIOLATION)

基本上,当遵循《Rust in Action:系统编程概念和技术》一书时,该材料实现了一个自定义分配器(它基本上调用系统分配器,但打印出分配时间等)。我以为我可以修改自定义分配器以将分配时间写入文件,这样我就可以使用 Pandas 进行一些 EDA,但这似乎失败了,因为我现在遇到了上述错误。

#[global_allocator]
static ALLOCATOR: ReportingAllocator = ReportingAllocator;
struct ReportingAllocator;

unsafe impl GlobalAlloc for ReportingAllocator{
    unsafe fn alloc(&self, layout : Layout) -> *mut u8{
        let start = Instant::now();
        let ptr = System.alloc(layout);
        let end = Instant::now();
        let time_taken = end - start;
        let bytes_requested = layout.size();
        //TODO: convert data to strings and pass to func
        let str_bytes = format!("{}", bytes_requested);
        let str_time = format!("{}", time_taken.as_nanos());
        log_data(str_bytes, str_time);
        // eprintln!("{}\t{}", bytes_requested, time_taken.as_nanos());
        return ptr;
    }

    unsafe fn …
Run Code Online (Sandbox Code Playgroud)

rust

1
推荐指数
1
解决办法
137
查看次数

SpringBoot Data Mongodb 与 Testcontainers 导致“过早到达流末尾”

它是在我将 SB 应用程序升级到 3.2.0 后开始的。我最初以为我的 spring 上下文有问题。因此,经过几天的碰壁之后,我终于决定尝试一些新的东西(而且是显而易见的):从一个新的 SB 应用程序开始。所以我去了https://start.spring.io/并创建了一个新的 SB 3.2.0,仅包含 web、mongodb 和 testcontainers,这给了我这个干净的 gradle 构建配置:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '21'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.boot:spring-boot-testcontainers'
    testImplementation 'org.testcontainers:junit-jupiter'
    testImplementation 'org.testcontainers:mongodb'
}

tasks.named('test') {
    useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)

到目前为止一切看起来都很好,所以我去了 spring 提供的演示测试文件并将其更改为:

@Testcontainers
@SpringBootTest
class DemoApplicationTests {

    @Container
    @ServiceConnection
    static MongoDBContainer mongoDBContainer = …
Run Code Online (Sandbox Code Playgroud)

spring spring-data spring-data-mongodb spring-boot spring-boot-testcontainers

6
推荐指数
0
解决办法
171
查看次数

如何在 Angular 服务中创建同步方法?

我有一个 Angular 15 应用程序,其中有一些组件调用服务方法从后端检索一些数据。在执行之前,服务会检查本地缓存中是否有所需的数据。如果没有数据,则服务执行端点并将检索到的数据存储在缓存中。在代码中看起来是这样的:

export class CryptoMarketService implements MarketService {
   private _activeOrdersCache: Cache<Array<Order>> = new Cache<Array<Order>>();
   ...
    getActiveOrders(): Observable<Array<Order>> {   // the method should be syncrhonized
       if (this._activeOrdersCache.hasCache()) {
           return of(this._activeOrdersCache.get());
       }

       return this.httpClient.get('/market/orders/active')
        .pipe(
            map((res: any) => {
                return Order.fromJsonArray(res);
            }),
            tap((activeOrders: Array<Order>) => {
                this._activeOrdersCache.set(activeOrders, 5, TimeUnit.MINUTES);
            })
        );
}
Run Code Online (Sandbox Code Playgroud)

但是一些组件同时调用该方法,因此实际上它们都在调用后端(因为缓存无法及时初始化),并且只有在获得响应后,缓存才会填充两次。那么有没有一种方法可以使该服务方法同步(就像在java中一样),使第二个线程等待第一个线程完成,并仅在缓存确定后才开始执行 getActiveOrders 方法?

Angular 是否有类似 Java 或 C# 中的同步机制?

observable rxjs typescript angular

2
推荐指数
1
解决办法
104
查看次数

为什么概念要求没有生效

在以下代码中,它在 -std=c++23 标志下编译。为什么概念要求 In 参数不应被引用触发?

#include <concepts>
#include <type_traits>
#include <functional>

template <typename T>
concept NotRef = requires { !std::is_reference_v<T>; };

template <typename In, typename Out>
    requires NotRef<In> // requires that In should not be reference
class SwitchType
{
    using ConstIn = std::add_const_t<In>;
public:
    SwitchType(const In& in)
        : in_{in}
    { }
    ConstIn & in_;
};

int main()
{
    int a{9};
    // Expected behavior: 'requirement not satifsfied'
    // Actural behavior: compiles under c++ 23

    SwitchType<int&, int> mytype{a};
}
Run Code Online (Sandbox Code Playgroud)

c++ c++-concepts c++23

2
推荐指数
1
解决办法
97
查看次数

如何测试多个变量并在 C# if 语句中单独对它们进行操作?

我的 C# 程序中有一些基本代码,其中使用 3 个 if 语句。

if (leftIndex >= imageList.Count - 1)
{
    leftIndex = 0;
}
if (middleIndex >= imageList.Count - 1)
{
    middleIndex = 0;
}
if (rightIndex >= imageList.Count - 1)
{
    rightIndex = 0;
}
Run Code Online (Sandbox Code Playgroud)

这对于代码本身来说效果很好,但我想知道如何简化它以单独作用于每个代码,以防我有更多变量需要使用。

c# if-statement

0
推荐指数
1
解决办法
92
查看次数

在 kotlin 中,Optional.of 不能使用泛型参数

为什么这不能编译?

fun <T> returnOptionalOf(t: T): Optional<T> {
    val optional: Optional<T> = Optional.of(t)
    return optional
}
Run Code Online (Sandbox Code Playgroud)

错误是

类型不匹配:推断类型为 T,但预期为 T 和 Any

如何让它发挥作用?

这编译得很好:

fun returnOptionalOfString(t: String): Optional<String> {
    val optional: Optional<String> = Optional.of(t)
    return optional
}
Run Code Online (Sandbox Code Playgroud)

kotlin

3
推荐指数
1
解决办法
126
查看次数