[英]Class to template error: invalid use of non-static data member
First question here so I hope it's a good one. 这里的第一个问题,所以我希望这是一个好问题。 I have two classes that have several instances of a template inside them.
我有两个类,其中有几个模板实例。 One (grades) is a friend to the other (students), yet when I try to access one of the templates from the other class I get this wonderful g++ error:
一个(年级)是另一个(学生)的朋友,但是当我尝试从另一个类访问一个模板时,却遇到了这个奇妙的g ++错误:
error: invalid use of non-static data member 'grades_table::term'
This is the first of a few. 这是少数几个中的第一个。 I've seen several questions asked in the same vein on here but in looking through them I can't figure out how to apply that information to my problem.
我在这里看到了几个同样的问题,但是在浏览这些问题时,我不知道如何将这些信息应用于我的问题。 Here's all the relevant code.
这是所有相关代码。
table_frame.h table_frame.h
class grades_table{
friend class students_table;
public:
grades_table();
int insert(int& temp_student_ID, std::string& temp_term,
int& temp_year, char& temp_grade);
void print(int select_cell = 0);
void select(std::string& attribute, std::string& identifier);
private:
int row_number;
table_column<int> student_ID;
table_column<std::string> term;
table_column<int> year;
table_column<char> grade;
};
tables.cpp tables.cpp
void students_table::print(bool join_id, int select_cell){
int column_stop;
column_stop = student_ID.column_depth();
row_number = 1;
if(select_cell != 0){
cout << "(" << student_ID.print(select_cell) << ",";
cout << first_name.print(select_cell) << ",";
cout << last_name.print(select_cell) << ")";
}
else if(join_id){
while(row_number <= column_stop){
//Keep it clean
if(row_number % 2 == 0){
cout << "\n";
}
cout << "(" << student_ID.print(row_number) << ",";
cout << first_name.print(row_number) << ",";
cout << last_name.print(row_number) << ",";
cout << grades::term.print(row_number) << ","; <<-----ERROR
cout << grades::year.print(row_number) << ","; <<-----ERROR
cout << grades::grade.print(row_number) << ")";<<-----ERROR
...
Any help is very much appreciated. 很感谢任何形式的帮助。
EDIT 编辑
Ok, so I changed 'grades_table' to an instance I created called 'grades'. 好的,所以我将“ grades_table”更改为我创建的名为“ grades”的实例。 But now it tells me that it hasn't been declared.
但是现在它告诉我它尚未被声明。 Here's the main file:
这是主文件:
database_control.cpp database_control.cpp
#include "table_frame.h"
using namespace std;
void input_output();
void database_actions(const string& command, const string& arguments);
void split(const string &s, char delim, int start, string& argument);
grades_table grades;
students_table students;
bool PROGRAM_EXIT = false;
... ...
Your compiler is right. 您的编译器是正确的。 You should create instance of
grades_table
and then only you can access non-static members. 您应该创建
grades_table
实例,然后只有您才能访问非静态成员。 I cannot see any static member in your class. 我看不到您班上的任何静态成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.