目录
// 错误#define FILE_H#include "file.h"#endif// 正确#define FILE_H#include "myfile.h"#endif
// 错误
#define FILE_H
#include "file.h"
#endif
// 正确
#include "myfile.h"
参考资料 error: expected ')' before '*' token
// 错误char* prt;prt = str;// 正确char* prt;prt = (char*)str;
char* prt;
prt = str;
prt = (char*)str;
// 错误// file: C.hclass C{};// file: main#include "C.h"static class C;... ...// 正确// file: C.hclass C{};// file: main#include "C.h"class C;... ...
// file: C.h
class C{
};
// file: main
#include "C.h"
static class C;
... ...
class C;
// 错误class C{ int func(){}};int c = C::func();... ...// 正确class C{ int func(){}};C temp;int c = temp.func();... ...
int func(){}
int c = C::func();
C temp;
int c = temp.func();
// 错误class C{ int a; int &r; C();};C::C(){ a = 1;}... ...// 正确class C{ int a; int &r; C();};C::C():r(a){ a = 1;}... ...
int a;
int &r;
C();
C::C(){
a = 1;
}
C::C():r(a){
// 错误#include<iostream>class C{private: int a;public: bool func(){ cout << "hello: " << this->a << endl; } C(const C& c){ c.func(); }};C c1;C c2(c1);// 正确#include<iostream>class C{private: int a;public: bool func() const{ cout << "hello: " << this->a << endl; } C(const C& c){ c.func(); }};C c1;C c2(c1);
#include<iostream>
private:
public:
bool func(){
cout << "hello: " << this->a << endl;
C(const C& c){
c.func();
C c1;
C c2(c1);
bool func() const{
参考资料 error: passing 'const …' as 'this' argument of '…' discards qualifiers error:passing 'const Student' as 'this' argument of 'void Student::print()' discards qualifiers
// 错误class C{ C(int a=1);}C::C(int a=1){;}// 正确class C{ C(int a=1);}C::C(int a){;}};
C(int a=1);
C::C(int a=1){;}
C::C(int a){;}
// 错误class C{ ... ...}// 正确class C{ ... ...};
#ifdef ×××× //定义一个宏,通常是该头文件名大写#define ××××#endif
#ifdef ×××× //定义一个宏,通常是该头文件名大写
#define ××××
// 定义C类// 错误C{ ... ...};// 正确class C{ ... ...};
// 定义C类
C{
// 错误// file: C.hclass C{ ... ...};// file: test.h#include "C.h"C test;... ...// 正确// file: C.hclass C{ ... ...};// file: test.h#include "C.h"class test;C test;... ...
// file: test.h
C test;
class test;
// 错误class C{ virtual C();};virtual C(){ ... ...}// 正确class C{ virtual C();};C(){ ... ...}
virtual C();
virtual C(){
C(){
// 错误const char* pathname = "hello.txt";oflag = O_RDWR|O_APPEND;this->_fd = open(const char* pathname, int oflag);// 正确const char* pathname = "hello.txt";oflag = O_RDWR|O_APPEND;int fd = open(pathname, oflag);
const char* pathname = "hello.txt";
oflag = O_RDWR|O_APPEND;
this->_fd = open(const char* pathname, int oflag);
int fd = open(pathname, oflag);
本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728