#AL.hpp
template <typename A>
class AL
{
public:
void print(A *source, A *dest, unsigned int size);
private:
A *data;
unsigned int size;
unsigned int capacity;
}
namespace {
template <typename A>
unsigned int size s_size = 20;
void print(A *source, A *dest, unsigned int size)
{
....
}
}
template <typename A>
AL<X>& AL<X>::push(A input)
{
capacity *= 2;
A *new_data = new A[capacity];
print(data, new_data, size);
}
我只是想知道如何格式化它(请不要介意代码)。当我运行我的完整代码时,它说 A 没有在命名空间中定义。我不确定如何将类模板传递到我的命名空间。
最佳答案
#AL.hpp
template <typename A>
class AL
{
public:
AL(A array_list);
AL(const AL& other);
AL& operator=(const AL& other);
~AL;
void print(A *source, A *dest, unsigned int size);
}
namespace {
unsigned int size s_size = 20;
template <typename A>
void print(A *source, A *dest, unsigned int size)
{
....
}
}
如果问题或错误是您的“打印”函数似乎未命名,那么这就是解决方案。我希望这会有所帮助。
关于c++ - 带有函数的c++类模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25196445/