奇怪的编译时错误:无法解析方法push_back
wierd compile time error: method push_back could not be resolved
我有以下一段代码处理向量中的向量。在使用 eclipse 时,我遇到了一个非常奇怪的编译时错误。
我正在尝试将column_info向量中现有条目的内容复制到新table_info向量中的新column_info向量。
typedef struct _column_info
{
char name[20]; // Column Name
int type; // 0:INT, 1: CHAR
int size;
int offset; // Start Position
} column_info;
typedef struct _table_info
{
char name[20]; // Table Name
char columns[100];
vector<column_info> col;
char primary_key[20];
int recordsize;
int totalsize;
int records;
} table_info;
vector<table_info> v;
table_info* get_table_info(const string& tablename)
{
for (int i = 0; i < (int) v.size(); i++)
{
if (strcmp(v.at(i).name, tablename.c_str()) == 0)
return &v.at(i);
}
return NULL;
}
void select_table_nested(char* tablename, char* select_column[], int column_cnt[], int nested_cnt, int select_column_count)
{
table_info* table_info;
table_info = get_table_info(tablename);
table_info new_table;
column_info cols;
for( int k =0; k < table_info->col.size(); k++)
{
strcpy(cols.name, table_info->col.at(k).name);
cols.type = table_info->col.at(k).type;
cols.size = table_info->col.at(k).size;
cols.offset = table_info->col.at(k).offset;
new_table.col.push_back(cols); ---> field 'col' could not be resolved
---> Method 'push_back' could not be resolved
}
}
我错过了什么吗?因为我正在同一代码的其他部分(在不同的函数中)执行push_back操作,并且没有收到此错误,除了在这个特定函数中。请帮忙。
这是第一个编译器错误吗?
table_info* table_info;
table_info = get_table_info(tablename);
table_info new_table;
在第一行中,您将创建一个局部变量table_info
,用于隐藏外部上下文中的类型table_info
。第三行应该是编译器错误,告诉您语法错误。从那里开始,无论编译器试图解释什么,都不会让它相信new_table
是 table_info
类型的对象。
你声明了一个名为 table_info
的变量,并且有一个名为 table_info
的类型,这混淆了编译器。当我通过 g++ 运行它时,它开始抱怨
table_info new_table;
因为此时table_info
是一个变量名,不再是类型名。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 使用std::函数映射对象方法
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- C++从另一个类访问公共静态向量的正确方法是什么
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 没有为自己的结构调用列表推回方法
- C++ push() 和 pop() 方法使用指针的动态 LinkedList 的问题
- 此C 链接列表/PUSH/POP程序的主要方法
- 向量上push方法的C++错误
- 向量resize(), push.back(), reserve()方法