在标头中声明 sqlite::d atabase db( ":memory:" ) 会给出错误
Declaring sqlite::database db(":memory:") in header gives error
我正在使用其github页面上提供的sqlite_modern_cpp开发示例程序。我正在使用内存数据库。
在我的最终应用程序中,我需要将此数据库存储为我班级的私人成员。将数据库对象sqlite::database db(":memory:");
称为私有时,我会遇到错误成员。当我将声明sqlite::database db(":memory:");
移至源文件时,错误将解决。
#include <memory>
#include <sqlite_modern_cpp.h>
class sqlitemoderncpp
{
private :
sqlite::database db(":memory:"); //Declaring in header gives error but all errors are resolved when moded to source file
public:
void run();
};
void sqlitemoderncpp::run(void)
{
try {
db <<
"create table if not exists user ("
" _id integer primary key autoincrement not null,"
" age int,"
" name text,"
" weight real"
");";
int age = 21;
float weight = 68.5;
std::string name = "jack";
this->db << "insert into user (age,name,weight) values (?,?,?);"
<< age
<< name
<< weight;
std::cout << "The new record got assigned id " << this->db.last_insert_rowid() << std::endl;
db << "select age,name,weight from user where age > ? ;"
<< 18
>> [&](int age, std::string name, double weight) {
std::cout << age << ' ' << name << ' ' << weight << std::endl;
};
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}
错误:
error C3867: 'sqlitecpp::db': non-standard syntax; use '&' to create a pointer to member
error C2296: '<<': illegal, left operand has type 'sqlite::database (__cdecl sqlitecpp::* )(void)'
error C2297: '<<': illegal, right operand has type 'const char [124]'
error C3867: 'sqlitecpp::db': non-standard syntax; use '&' to create a pointer to member
error C2296: '<<': illegal, left operand has type 'sqlite::database (__cdecl sqlitecpp::* )(void)'
error C2297: '<<': illegal, right operand has type 'const char [51]' error
C3867: 'sqlitecpp::db': non-standard syntax; use '&' to create a pointer to member error C2296: '<<': illegal, left operand has type 'sqlite::database (__cdecl sqlitecpp::* )(void)'
error C2297: '<<': illegal, right operand has type 'const char [49]'
默认成员初始化程序(自C 11(仅适用于Brace或Equals Initializer。您可以将其更改为
sqlite::database db{":memory:"};
或
sqlite::database db = sqlite::database(":memory:");
在C 11之前,您可以添加带有成员初始化器列表的构造函数。
class sqlitemoderncpp
{
private :
sqlite::database db;
public:
void run();
sqlitemoderncpp() : db(":memory:") {}
};
相关文章:
- 警告处理为错误这里有什么问题
- Win32 API - HWND "{unused = ???} Unable to read memory"错误
- Java 本机访问代码错误:"Invalid memory access"
- 如何修复代码中的"Invalid memory reference"错误?
- 在标头中声明 sqlite::d atabase db( ":memory:" ) 会给出错误
- 使用 system(命令) 时,C++代码在 AWS 中失败,并出现错误"cannot allocate memory"
- 视觉奇怪"Memory Leak Detection"错误C++
- 如何在中等规模的项目中诊断g ++错误"cc1plus.exe: out of memory allocating 838860800 bytes"?
- 什么可能导致错误:"Fatal Error: Out of memory - aborting"简单地包含头文件?
- 在 Linux 上的源文件上运行'gcc' C++会给出"cc1plus: out of memory allocating ..."错误消息
- 错误:arma::memory::acquire():犰狳的内存不足
- 推力变换引发错误:"bulk_kernel_by_value: an illegal memory access was encountered"
- Dr.Memory发现的错误:不知道如何解决
- C++ DLL 到 C# 错误:"Attempted to read or write protected memory. This is often an indication that other
- 简单的 CUDA 测试总是失败并出现错误"an illegal memory access was encountered"
- 如何解决 c++ 中mysql_init过程中"insufficient memory"的 mysql 错误?
- 在Qt中出现"Physical Memory currently used by current process"错误
- 矢量存储限制的向量 - 获得"Microsoft C++ exception: std::bad_alloc at memory location 0x0031650C."错误
- 等效于 VB DLL 函数声明的 C# 返回并返回'Attempted to read or write protected memory'错误
- 为什么 Linux msync 会返回"Cannot Allocate memory"?是否可以修复此错误代码?