小白问个问题,关于编译失败的

C++语言 码拜 7年前 (2017-04-12) 999次浏览
Screem.h文件中
#pragma once
#include<string>
using std::string;
#include<vector>
class screem
{
public:
typedef string::size_type pos;
screem() = default;
screem(pos ht, pos wd) : height(ht), width(wd), contents(ht*wd, ” “) {};
screem(pos ht, pos wd, char c) :height(ht), width(wd), contents(ht*wd, c){};
screem& set(char);
screem& set(pos, pos , char);
void some_member() const;
char get() const { return contents[cursor]; }
inline char get(pos ht, pos wd) const;
screem &move(pos r, pos c);
screem& display(std::ostream &os)
{
do_display(os);
return *this;
}
const screem& display(std::ostream &os) const
{
do_display(os);
return *this;
}
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
mutable size_t access_ctr;
void do_display(std::ostream& os) const
{
os << contents;
}
};
class Window_mgr
{
private:
std::vector<screem> screems{ screem(24,80) };
};
Screem.cpp中
#include”Screem.h”
inline
screem &screem::move(pos r, pos c)
{
pos row = r*width;
cursor = row + c;
return *this;
}
char screem::get(pos r, pos c) const
{
pos row = r*width;
return contents[row + c];
}
void screem::some_member() const
{
++access_ctr;
}
inline screem& screem::set(char c)
{
contents[cursor] = c;
return *this;
}
inline screem& screem::set(pos r, pos col, char c)
{
contents[r*width + col] = c;
return *this;
}
MAIN.cpp中
#include”Person_.h”
#include”Screem.h”
int main()
{
screem MyScreem(5, 5, “5”);
MyScreem.move(4, 0);
MyScreem.set(3,2,” “);
MyScreem.display(cout);
cout << “\n”;
MyScreem.display(cout);
cout << “\n”;
while (1);
}
编译结果
1>– 已启动生成: 项目: Person_, 配置: Debug Win32 —
1>  MAIN.cpp
1>MAIN.obj : error LNK2019: 无法解析的外部符号 “public: class screem & __thiscall screem::set(unsigned int,unsigned int,char)” (?set@screem@@QAEAAV1@IID@Z),该符号在函数 _main 中被引用:

MyScreem.move(4, 0);
MyScreem.set(3,2,” “);
//改为
MyScreem.move((pos)4, (pos)0);
MyScreem.set((pos)3,(pos)2,” “);

类型问题 应该不会提示这错误吧

60

去掉全部inline关键字
内联函数只能在看的到地方用,你在A.cpp中的内联函数在B.cpp中是看不到的

5

看起来像是screen.cpp没被编译,或编译后没被链接进来。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明小白问个问题,关于编译失败的
喜欢 (0)
[1034331897@qq.com]
分享 (0)