抓狂的c++错误:...which is of non-class type..
2016-01-16 14:45
501 查看
代码如下:
恶心,非常恶心,这种错误太古怪了,让人觉得这语言太难用了,话费的编译调试成本也太大了….,无语了,看解决方法,将g++贴换成clang++尝试编译(为什么用clang,因为clang能打印出更好的错误提示信息),看具体提示
按照提示加上之后编译通过,我猜可能编译器把这个定义只当做了函数声明,而没有把它当做一个类的定义。
类似问题后来我google一下发现有人也撞上了,但是他(她)解释的更清楚一些,链接如下
http://dehun.bitbucket.org/articles/23_oct_2013-Error%20which%20is%20of%20non-class%20type.html
//sqlite_interface.h class SqlteOp { private: sqlite3 *db; public: SqlteOp(string dbname); ~SqliteOp(); void print(); } //sqlite_interface.cpp SqliteOp::SqliteOp(string dbname) { cout<<"db name is: "<<dbname<<endl; sqlite3_open(dbname.c_str(), &db); ... } SqliteOp::print() { cout<<"Sqlite Operation print function"<<endl; ... } SqliteOp::~SqliteOp() { cout<<"destroy sqlite op object"<<endl; sqlite3_close(db); } //main.cpp int main(int argc, char **argv) { SqliteOp sqliteOp(string(argv[1])); sqliteOp.print(); return 0; } //编译 dk@dkos:~ g++ --std=c++11 main.cpp sqlinteop.cpp -I /usr/local/include -L /usr/local/lib -lsqlite3 -lpthread -ldl //报错 main.cp:14:13: error: request for member 'print' in 'sqliteOp', which is of non-class type.......
恶心,非常恶心,这种错误太古怪了,让人觉得这语言太难用了,话费的编译调试成本也太大了….,无语了,看解决方法,将g++贴换成clang++尝试编译(为什么用clang,因为clang能打印出更好的错误提示信息),看具体提示
dk@dkos:~ clang++ --std=c++11 main.cpp sqlinteop.cpp -I /usr/local/include -L /usr/local/lib -lsqlite3 -lpthread -ldl //提示如下 main.cpp:14:23: note: add a pair of parentheses to declare a variable SqliteOp sqliteOp(string(argv[1])); ^ ( )
按照提示加上之后编译通过,我猜可能编译器把这个定义只当做了函数声明,而没有把它当做一个类的定义。
类似问题后来我google一下发现有人也撞上了,但是他(她)解释的更清楚一些,链接如下
http://dehun.bitbucket.org/articles/23_oct_2013-Error%20which%20is%20of%20non-class%20type.html
相关文章推荐
- 如何组织构建多文件 C 语言程序(二)
- 如何写好 C main 函数
- Lua和C语言的交互详解
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解
- C语言内存对齐实例详解
- C语言编程中统计输入的行数以及单词个数的方法
- C语言自动生成enum值和名字映射代码
- 使用C语言判断英文字符大小写的方法
- c语言实现的带通配符匹配算法
- C语言实现顺序表基本操作汇总
- C语言中计算正弦的相关函数总结
- 使用C语言详解霍夫曼树数据结构
- 探讨C语言的那些小秘密之断言
- C语言实现BMP转换JPG的方法
- 深入探讨C语言中局部变量与全局变量在内存中的存放位置
- C语言查找数组里数字重复次数的方法