[英]invalid use of non-static data member error with template friend functions c++
[英]Class to template error: invalid use of non-static data member
這里的第一個問題,所以我希望這是一個好問題。 我有兩個類,其中有幾個模板實例。 一個(年級)是另一個(學生)的朋友,但是當我嘗試從另一個類訪問一個模板時,卻遇到了這個奇妙的g ++錯誤:
error: invalid use of non-static data member 'grades_table::term'
這是少數幾個中的第一個。 我在這里看到了幾個同樣的問題,但是在瀏覽這些問題時,我不知道如何將這些信息應用於我的問題。 這是所有相關代碼。
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
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
...
很感謝任何形式的幫助。
編輯
好的,所以我將“ grades_table”更改為我創建的名為“ grades”的實例。 但是現在它告訴我它尚未被聲明。 這是主文件:
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;
...
您的編譯器是正確的。 您應該創建grades_table
實例,然后只有您才能訪問非靜態成員。 我看不到您班上的任何靜態成員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.