抓狂的c++错误:...which is of non-class type..

代码如下:

//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

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值