Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 标题中的模板不允许我使用我的类?_C++_Templates - Fatal编程技术网

C++ 标题中的模板不允许我使用我的类?

C++ 标题中的模板不允许我使用我的类?,c++,templates,C++,Templates,非常新的模板,我的教授是可怕的教学他们,所以我试图学习它自己。看了几个视频,我似乎不明白我做错了什么。当我取出模板时,我的整个代码都会编译,但一旦我添加了代码 //将所有以前的int替换为T template <typename T> class Checks { public: int ispair(vector<T> dvalues); int flush(Vector<T> dsuits); int straight(vector<T> dv

非常新的模板,我的教授是可怕的教学他们,所以我试图学习它自己。看了几个视频,我似乎不明白我做错了什么。当我取出模板时,我的整个代码都会编译,但一旦我添加了代码

//将所有以前的int替换为T

template <typename T>
class Checks
{
public:
int ispair(vector<T> dvalues);
int flush(Vector<T> dsuits);
int straight(vector<T> dvalues);
int threeofakind(vector<T> dvalues);
int fourofakind(vector<T> dvalues);
int fullhouse(vector<T> dvalues);
Checks(); //didn't include all of header since there's a lot more want to save room
}
我得到这个错误:检查没有合适的默认构造函数可用


很明显,我的模板制作方式有问题,有什么建议或帮助吗?

只是猜测,因为我不精通CPP,但您在定义变量时,需要指定类的类型:

Checks<int> ck1;
检查ck1;

只是一个猜测,因为我不精通CPP,但您在定义变量时,需要指定类的类型:

Checks<int> ck1;
检查ck1;
您有3个问题

  • 您忘记在vector之前添加std::了
  • 一个向量是写向量而不是向量
  • 你没有用}结束你的课程

    #include <vector>
    
    template <typename T>
    class Checks {
    public:
        int ispair(std::vector<T> dvalues);
        int flush(std::vector<T> dsuits); //was Vector
        int straight(std::vector<T> dvalues);
        int threeofakind(std::vector<T> dvalues);
        int fourofakind(std::vector<T> dvalues);
        int fullhouse(std::vector<T> dvalues);
    
    }; //didn'T close the class with };
    
    #包括
    模板
    等级检查{
    公众:
    int ispair(标准:矢量数据值);
    int flush(std::vector dsuits);//was vector
    int直线(标准:向量D值);
    int三类(std::向量d值);
    int-fourofakind(std::vector-dvalues);
    int fullhouse(标准:向量值);
    }; //没有使用}关闭类;
    
**编辑**

int main(int argc, char** argv) {
    Checks<int> check;
    std::vector<int> v;
    check.ispair(v);
    return EXIT_SUCCESS;
}
int main(int argc,char**argv){
检查;
std::向量v;
检查ispair(v);
返回退出成功;
}
检查

#include <vector>

template <typename T>
class Checks {
public:
    int ispair(std::vector<T> dvalues);
};

template<class T>
int Checks<T>::ispair(std::vector<T> dvalues) {
    return 0;
}
#包括
模板
等级检查{
公众:
int ispair(标准:矢量数据值);
};
模板
int Checks::ispair(标准::向量dvalues){
返回0;
}
您有3个问题

  • 您忘记在vector之前添加std::了
  • 一个向量是写向量而不是向量
  • 你没有用}结束你的课程

    #include <vector>
    
    template <typename T>
    class Checks {
    public:
        int ispair(std::vector<T> dvalues);
        int flush(std::vector<T> dsuits); //was Vector
        int straight(std::vector<T> dvalues);
        int threeofakind(std::vector<T> dvalues);
        int fourofakind(std::vector<T> dvalues);
        int fullhouse(std::vector<T> dvalues);
    
    }; //didn'T close the class with };
    
    #包括
    模板
    等级检查{
    公众:
    int ispair(标准:矢量数据值);
    int flush(std::vector dsuits);//was vector
    int直线(标准:向量D值);
    int三类(std::向量d值);
    int-fourofakind(std::vector-dvalues);
    int fullhouse(标准:向量值);
    }; //没有使用}关闭类;
    
**编辑**

int main(int argc, char** argv) {
    Checks<int> check;
    std::vector<int> v;
    check.ispair(v);
    return EXIT_SUCCESS;
}
int main(int argc,char**argv){
检查;
std::向量v;
检查ispair(v);
返回退出成功;
}
检查

#include <vector>

template <typename T>
class Checks {
public:
    int ispair(std::vector<T> dvalues);
};

template<class T>
int Checks<T>::ispair(std::vector<T> dvalues) {
    return 0;
}
#包括
模板
等级检查{
公众:
int ispair(标准:矢量数据值);
};
模板
int Checks::ispair(标准::向量dvalues){
返回0;
}

你没有用}结束你的课程;你没有和}结业;虽然我非常感谢您查看我的代码,但如果您查看我编写的代码,我并没有包含整个.h文件。显然,我必须用“;”来结束我的课程,我不需要放置std,因为我已经在使用那个名称空间了。我的问题更多的是关于模板语法,所有这些在没有我的模板实现的情况下都已经起作用了,这就是我的问题所在。抱歉,我只是想澄清一下,并不是说听起来不合理,只是想让大家更清楚。虽然我非常感谢您查看我的代码,但如果您查看我编写的代码,我并没有包括整个.h文件。显然,我必须用“;”来结束我的课程,我不需要放置std,因为我已经在使用那个名称空间了。我的问题更多的是关于模板语法,所有这些在没有我的模板实现的情况下都已经起作用了,这就是我的问题所在。抱歉只是想澄清一下,并不是说听起来不理性,只是想让人们更清楚。