未定义的标识符,明明定义了啊。。
头文件
*****************************************************************8
#ifndef TOUTOU_H
#define TOUTOU_H
#include<iostream>
#include<string>
using namespace std;
using std::iostream;
using std::string;
using std::cout;
class Screen {
public:
using pos = std::string::size_type;
Screen() = default;
Screen(pos ht, pos wd) :height(ht), width(wd), conents(ht*wd, ' ') {}
Screen(pos ht, pos wd, char c) :height(ht), width(wd), conents(ht*wd, c) {}
char get() const { return conents[cursor]; } *********** cursor未定义
char get(pos r, pos s) const { return conents[r*width + s]; }
Screen &move(pos r, pos s);
Screen &set(char c);
Screen &set(pos r, pos s, char c);
const Screen &display(std::ostream &os) const { do_display(os); return *this; }
Screen &display(std::ostream &os) { do_display(os); return *this; }
private:
void do_display const (ostream &os) {
os << conents;
}
private:
pos cursor = 0;
pos height = 0;
std::string conents;
pos width = 0;
};
inline Screen& Screen::move(pos r, pos s) {
cursor = r*width + s;
return *this;
}
inline Screen& Screen::set(char c) {
conents[cursor] = c;
return *this;
}
inline Screen& Screen::set(pos r, pos s, char c) {
conents[r*width + s] = c;
return *this;
}
#endif
程序
**********************************************************************
#include"C:\Users\Jin\Desktop\toutou.h"
int main()
{
Screen myScreen(5,5,'X'); ******************* Screen未定义
myScreen.move(4, 0).set('#').display(cout); ******************* cout未定义
cout << "\n";
myScreen.display(cout);
cout << "\n";
return 0;
}