目錄ios
CLRead read_buff()
就是一種錯誤的構造,致使read_buff沒法被識別, 出現note: no known conversion for argument 1 from ‘CLRead (*)()’ to ‘CLRead*’
;// 錯誤 #define FILE_H #include "file.h" #endif // 正確 #define FILE_H #include "myfile.h" #endif class CLFileBuff; // 聲明後才能使用,要否則也會出現這類錯誤
參考資料
error: expected ')' before '*' tokenc++
// 錯誤 char* prt; prt = str; // 正確 char* prt; prt = (char*)str;
// 錯誤 // file: C.h class C{ }; // file: main #include "C.h" static class C; ... ... // 正確 // file: C.h class C{ }; // file: main #include "C.h" class C; ... ...
// 錯誤 class C{ int func(){} }; int c = C::func(); ... ... // 正確 class C{ int 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; } ... ...
// 錯誤 #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);
參考資料
error: passing 'const …' as 'this' argument of '…' discards qualifiers
error:passing 'const Student' as 'this' argument of 'void Student::print()' discards qualifiersexpress
// 錯誤 class C{ C(int a=1); } C::C(int a=1){;} // 正確 class C{ C(int a=1); } C::C(int a){;} };
// 錯誤 class C{ ... ... } // 正確 class C{ ... ... };
#ifdef ×××× //定義一個宏,一般是該頭文件名大寫 #define ×××× #endif
// 定義C類 // 錯誤 C{ ... ... }; // 正確 class C{ ... ... };
// 錯誤 // file: C.h class C{ ... ... }; // file: test.h #include "C.h" C test; ... ... // 正確 // file: C.h class C{ ... ... }; // file: test.h #include "C.h" class test; C test; ... ...
// 錯誤 class C{ virtual C(); }; virtual C(){ ... ... } // 正確 class 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);