小编wan*_*yde的帖子

如何将类类型作为参数传递给新操作的函数模板?

我有一段 C++ 代码:

#include <iostream>
#include <string>
#include <map>

static counter = 0;

class Probe
{
private:
    int supply_;
    Probe(const Probe&);

public:
    Probe()
    {
        supply_ = 10000;
    }

    int get_supply()
    {
        return supply_;
    }

};

/********************************************************************************
template<class T> T Create(int counter, T& produced)
{
    produced[counter] = new ; // ??????????????????????????????????????
    return produced;
}
************************************************************************************/

std::map<int, Probe*> CreatInitWorkers(int counter, std::map<int, Probe*> &init_workers) 
{
    init_workers[counter] = new Probe(); 
    return init_workers;
}


int main()
{ 
    std::map<int, Probe*> workers;
    for (int i = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ class new-operator function-templates

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

标签 统计

c++ ×1

class ×1

function-templates ×1

new-operator ×1