Answer the question
In order to leave comments, you need to log in
Why does the compiler not see the class method?
The add_element_from_console() method is described in the ChymTable.h header file and implemented in ChymTable.cpp. When I try to use this method in the body of the program, the compiler throws an error "the ChymTable class does not contain a member add_element_from_console()". What could be the problem?
Here is the ChymTable.h file:
#ifndef ChymTable_H
#define ChymTable_H
#include "Element.h"
#include <string>
#include <fstream>
class ChymTable {
private:
int max_num_elements;
int num_elements;
Element *element;
public:
ChymTable(unsigned int max_el);
~ChymTable();
void add_element(Element aelement);
void add_element_from_console();
void read_from_file(string filename);
void write_to_file(string filename);
void display_all();
void find_element_by_mass(float amass);
void find_metalls();
};
#endif
#include "ChymTable.h"
#include <iostream>
#include "stdafx.h"
//...реализация других ф-ций
void ChymTable::add_element_from_console() {
element[num_elements].read_from_console();
num_elements++;
}
//...реализация других ф-ций
#include <string>
#include <locale>
#include <Windows.h>
#include "stdafx.h"
#include "Element.h"
#include "Element.cpp"
#include "ChymTable.h"
#include "ChymTable.cpp"
#include <fstream>
#include <iostream>
using namespace std;
int main(){
//код
table.add_element_from_console(); //здесь возникает ошибка (компилятор не видит метод)
//остальной код
}
Answer the question
In order to leave comments, you need to log in
you are connecting the files incorrectly
so it is unnecessary to do so.
#include "ChymTable.h"
#include "ChymTable.cpp"
you should only include headers (if they come with cpp)
write rules for make or just list all *.cpp for compiler
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question