我敢肯定有一个非常简单的答案,但是我无法弄清楚。我已经写了一个模板类,但是我想在没有模板的类函数中通过引用通过该类。这是我拥有的。我遇到了很多错误。我需要做的就是弄清楚如何格式化将模板类插入功能的方式,但是我丢失了。谢谢,很抱歉,如果代码真的没有帮助您。
#include <iostream>
using namespace std;
template <typename T>
class Foo {
public:
Foo();
insert(const T& Item)
//And other function, just examples
};
class noFoo(){
void test(Foo <T>& foo);
int i;
int j;
int k
};
template <typename T>
void noFoo::test(Food <T>& foo)}
cout << "hi";
}
int main() {
Foo<char> wr;
test(wr);
return 0;
}
使test
成为函数模板。我还为您纠正了语法错误的负载( class noFoo()
?),删除了不必要的代码,并为缩进了clang-format
。
#include <iostream>
template <typename T>
class Foo {};
class noFoo
{
public:
template <typename T>
void test(Foo<T> &);
};
template <typename T>
void noFoo::test(Foo<T> &)
{
std::cout << "hin";
}
int main()
{
Foo<char> wr;
noFoo{}.test(wr);
}
由于您的问题被标记为d,因此在此处使用相同的代码
import std.stdio;
class Foo(T) {};
class noFoo
{
public:
void test(T)(Foo!(T))
{
writeln("hi");
}
};
void main()
{
auto wr = new Foo!char;
(new noFoo).test(wr);
}