小编dge*_*low的帖子

去学习资源

我正在寻找资源开始使用go语言.

我知道go是一种非常新的语言,但是你不知道教程,文档或书籍来学习吗?你开始的方式是什么?

go

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

如何使用 C++ 模块:带有模板的私有片段?

我正在尝试 C++20,以更好地了解它们在实践中的工作原理。我了解了module :private可用于将接口与实现分离的片段,同时将两者保留在同一个文件中。这似乎适用于标准函数,但不适用于模板函数。

我有以下文件:

// File "main.cpp"

#include <iostream>

import mymodule;

int main()
{
    std::cout << "greeting(): " << mymodule::greetings() << std::endl;
    int x = 1;
    int y = 2;
    std::cout << "add(x, y): " << mymodule::add(x, y) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
// File "mymodule.ixx"

module;

#include <string>

// declare interface
export module mymodule;

export namespace mymodule {
    template<typename T>
    T add(T x, T y);

    std::string greetings();
}

// implement interface
module :private;

std::string mymodule::greetings() {
    return "hello";
} …
Run Code Online (Sandbox Code Playgroud)

c++ templates constexpr c++20 c++-modules

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

标签 统计

c++ ×1

c++-modules ×1

c++20 ×1

constexpr ×1

go ×1

templates ×1