C++ 未定义的类,无法从main到达我的标题

C++ 未定义的类,无法从main到达我的标题,c++,class,undefined,member,C++,Class,Undefined,Member,我有一个问题,我不能在标题中找到我的函数,我想在我的主函数中调用它,但它说。 错误2错误C2039:“测试”:不是“std::basic_字符串”的成员 未定义的类为什么会发生这种情况? 注意:我会删除代码中不重要的部分 #include "CompressHeader.h" int main() { input.get(ch); string a=ch; if(Test(a))//here is undefined one.

我有一个问题,我不能在标题中找到我的函数,我想在我的主函数中调用它,但它说。 错误2错误C2039:“测试”:不是“std::basic_字符串”的成员 未定义的类为什么会发生这种情况? 注意:我会删除代码中不重要的部分

 #include "CompressHeader.h"
    int main()
    {     input.get(ch);
         string a=ch;
            if(Test(a))//here is undefined one.
            {
             }
我的头球

class Compress
{
public:
    Compress();
   Compress(string hashData[],const int size); //constructor
    void makeEmpty();
    bool Test(string data);//To test if data in the dictionary or not.

因为Test是Compress的成员函数,所以需要通过Compress的实例调用,如:

string a=temp2;
Compress c;
if (c.Test(a)) {...}
或者将此代码放在下面代码中的Compress

的成员函数中:

if(Test(a))//here is undefined one.
调用一个全局函数
Test
——它实际上是
Compress
类的成员。因此,要修复代码,您应该调用压缩对象上的测试:

Compress c;
if (c.Test(a)){}

由于要调用的方法不是
静态
方法,因此需要创建类
Compress
的对象(实例)来调用该方法,例如:

#include "CompressHeader.h"
int main()
{
    // temp2 is not defined in your example, i made it a string
    string a = "temp2";

    //Create the object
    Compress compressObject;
    //Call the method using the object
    if(compressObject.Test(a) {
    //...

temp2
来自何处?请用a或它来自ifstream输入。get(ch)@M.J.Watson
if(Test(a))
没有这样的
测试。有一个
Compress::Test
,但该函数不是您试图在
main
中调用的函数。