gpt4 book ai didi

c++/ubuntu - 模板错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:42:09 25 4
gpt4 key购买 nike

我有以下代码:文件.h:

#ifndef __ANA_H__
#define __ANA_H__

template <class T>
class ana {

class ana1{//code
}*anna1;

public:
bool method(T& data,ana::ana1 &a);
};

#endif

文件.cpp:

#include <ana.h>
#include <iostream>
using namespace std;

template <class T>
bool ana<T>::method(T& data,ana::ana1 &t) {
cout << "Data = " << data << endl;
if(data > 0) {
return true;
}
return false;
}

我有错误:ana::ana1 不是类型。如何解决这个错误?我哪里错了?需要一些帮助。thx我在 ubuntu 工作,我使用 g++ 编译代码。我从我发布的 .h 和 .cpp 创建了一个 .a。

最佳答案

做那个

// (declaration):
bool method(T& data, ana1& t);

// (definition):
bool ana<T>::method(T& data, typename ana<T>::ana1& t) {

关于c++/ubuntu - 模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5948266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com