小编Meg*_*les的帖子

使用模板的方法嵌套结构

我想将python嵌套的defs翻译成c ++,我正在使用嵌套的结构.

#include<iostream>
static void ffunc(int x, int y)
{
    static int x1 = x;
    static int y1 = y;
    struct g
    {
        static void gfunc(int z)
        {
            static int z1 = z;
            std::cout << x1 << y1 << z << std::endl;

            struct h
            {
                static void hfunc(int k)
                {
                    std::cout<< x1 << y1 << z1 << k <<  std::endl;
                }
            };
            h::hfunc(4);
        }
    };
    g::gfunc(3);
}
int main()
{
    ffunc(1, 2);
}
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常.问题是,我想要模板,以便嵌套函数可以使用任何类型参数.但是,当我尝试使用模板时:

#include<iostream>
template <typename t1>
static void …
Run Code Online (Sandbox Code Playgroud)

c++ struct

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

标签 统计

c++ ×1

struct ×1