有问题
c4droid吧
全部回复
仅看楼主
level 8
Zetabill 楼主
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class Screen{
private:
unsigned wd=0,ht=0;
string centents;
int cursor=0;
public:
Screen()=default;
Screen(unsigned w,unsigned h):ht(h),wd(w){};
Screen(unsigned w,unsigned h,char c):ht(h),wd(w),centents(c){};
public:
Screen& move(unsigned r,unsigned c){
cursor=r*wd+c;
return *this;
}
Screen& set(char ch){
contents[cursor]=ch;
return *this;
}
Screen& set(unsigned r,unsigned c,char ch){
contents[r*wd+c]=ch;
return *this;
}
Screen& display(){
cout<<contents;
return *this;
}
};
int main(){
Screen my(5,5,'X');
my.move(4,0).set('#').display(cout);
cout<<endl;
my.display(cout);
return 0;
}
7 15 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids initialization of member 'wd' [-fpermissive]
7 15 D:\我的文档\未命名2.cpp [Error] making 'wd' static [-fpermissive]
7 15 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids in-class initialization of non-const static member 'wd'
7 20 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids initialization of member 'ht' [-fpermissive]
7 20 D:\我的文档\未命名2.cpp [Error] making 'ht' static [-fpermissive]
7 20 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids in-class initialization of non-const static member 'ht'
9 14 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids initialization of member 'cursor' [-fpermissive]
9 14 D:\我的文档\未命名2.cpp [Error] making 'cursor' static [-fpermissive]
9 14 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids in-class initialization of non-const static member 'cursor'
12 3 D:\我的文档\未命名2.cpp [Error] 'Screen::Screen(unsigned int, unsigned int)' cannot be overloaded
11 3 D:\我的文档\未命名2.cpp [Error] with 'Screen::Screen(unsigned int, unsigned int)'
15 7 D:\我的文档\未命名2.cpp [Error] ISO C++ forbids declaration of 'out' with no type [-fpermissive]
D:\我的文档\未命名2.cpp In constructor 'Screen::Screen(unsigned int, unsigned int)':
12 33 D:\我的文档\未命名2.cpp [Error] 'unsigned int Screen::ht' is a static data member; it can only be initialized at its definition
12 39 D:\我的文档\未命名2.cpp [Error] 'unsigned int Screen::wd' is a static data member; it can only be initialized at its definition
D:\我的文档\未命名2.cpp In constructor 'Screen::Screen(unsigned int, unsigned int, char)':
13 43 D:\我的文档\未命名2.cpp [Error] 'unsigned int Screen::ht' is a static data member; it can only be initialized at its definition
13 49 D:\我的文档\未命名2.cpp [Error] 'unsigned int Screen::wd' is a static data member; it can only be initialized at its definition
13 65 D:\我的文档\未命名2.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]
214 5 c:\program files\dev-cpp\mingw32\lib\gcc\mingw32\4.6.2\include\c++\bits\basic_string.tcc [Error] initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' [-fpermissive]
D:\我的文档\未命名2.cpp In member function 'int Screen::out()':
17 12 D:\我的文档\未命名2.cpp [Error] cannot convert 'Screen' to 'int' in return
为啥要把private里的东西给静态了?
静态不就没法改动了?
改了也不对,怎么破?
2016年05月18日 07点05分 1
level 2
不要迷恋哥,哥只是传说
2016年05月19日 11点05分 2
level 8
Zetabill 楼主
这是咋?
2016年05月19日 14点05分 3
level 8
Zetabill 楼主
自顶
2016年05月21日 05点05分 4
1