小编raj*_*raj的帖子

c ++中的类方法错误

我在宣布课时遇到错误:

#include <iostream>
#include "testing/test.h"
#include <string>
using namespace std;

int main(void)
{    
    test links;
    string content="this is an string";
    links.getcont(content);
}
Run Code Online (Sandbox Code Playgroud)

test.h

#ifndef TEST_H_
#define TEST_H_
#include<string>
using namespace std;
class test {    
  public:    
    string getcont(string content); 

};

#endif /* TEST_H_ */
Run Code Online (Sandbox Code Playgroud)

TEST.CPP

#include "test.h"
#include <iostream>
using namespace std;    
string getcont(string content)    
{
    cout << content;
    return content;
}
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到此错误:

undefined reference to test::getcont(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
124
查看次数

标签 统计

c++ ×1