There are two classes:

class ChangeButton { public: ChangeButton(string ButtonCode, int ButtonType) { btn_code = ButtonCode; btn_type = ButtonType; } std::string get_btn_code() { return btn_code; } int get_btn_type() { return btn_type; } private: std::string btn_code; int btn_type; }; class Change { public: Change(list<ChangeButton> Change_Button, list<ChangeButton> Change_To_Button) { change_btn_list = Change_Button; change_to_btn_list = Change_To_Button; } list<ChangeButton> get_list_change_btn() { return change_btn_list; } list<ChangeButton> get_list_change_to_btn() { return change_to_btn_list; } private: list<ChangeButton> change_btn_list; list<ChangeButton> change_to_btn_list; }; 

In the code I need:

 list<Change> Changes; list<ChangeButton> ChangeButtons; list<ChangeButton> ChangeToButtons; 

When compiling a project, numerous errors pop up like: Change an undeclared identifier, a symbol is neither a template class, nor a function template, etc.

I am new to C ++, so I’m doing something like C #.

What is my mistake, please tell me. I would be grateful if you show an example.


 // JsonReader.cpp: определяет точку входа для консольного приложения. // #include "stdafx.h" #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/istreamwrapper.h" #include <iostream> #include <string> #include <fstream> #include <list> using namespace rapidjson; using namespace std; int main() { list<Change> Changes; list<ChangeButton> ChangeButtons; list<ChangeButton> ChangeToButtons; ifstream ifs("json.js"); IStreamWrapper isw(ifs); Document documentFromFile; documentFromFile.ParseStream(isw); Value& arr = documentFromFile["changes"]; // open the "changes" tag if (arr.IsArray()) { for (SizeType i = 0; i < arr.Size(); i++) // foreach the "changes" tag { Value& changes = arr[i]; Value& change_btns = changes["change_btns"]; if (change_btns.IsArray()) { for (SizeType i = 0; i < change_btns.Size(); i++) // { Value& btn = arr[i]; cout << btn.GetType() << '\n'; } } } } system("pause"); return 0; } class ChangeButton { public: ChangeButton(string ButtonCode, int ButtonType) { btn_code = ButtonCode; btn_type = ButtonType; } std::string get_btn_code() { return btn_code; } int get_btn_type() { return btn_type; } private: std::string btn_code; int btn_type; }; class Change { public: Change(list<ChangeButton> Change_Button, list<ChangeButton> Change_To_Button) { change_btn_list = Change_Button; change_to_btn_list = Change_To_Button; } list<ChangeButton> get_list_change_btn() { return change_btn_list; } list<ChangeButton> get_list_change_to_btn() { return change_to_btn_list; } private: list<ChangeButton> change_btn_list; list<ChangeButton> change_to_btn_list; }; 
  • included headlines? namespace? - academ
  • Um I can not answer, but the classes are in the executable file. - Llirik 21
  • #include <list> , #include <string> , using std::list , using std::string - acade
  • #include <list>, #include <string>, using namespace std, but errors still persist - Llirik 21
  • in the project one file? if not, add information on how other files are included, where the main function is defined - acade

1 answer 1

Classes need to be declared before use. Functions and member functions can be pre-declared, for example:

 class Foo{ int v; public: Foo(int); } int main(){ //.... } Foo::Foo(int v){ //... } 

Better yet, put the ads in the header file.

Edit: The classes themselves can also be pre-declared, but only links and pointers to them are available and their dereference is prohibited.

  • Thank you very much, it helped! - Llirik 21
  • "Pre" in this case will not work. - AnT