I am making my first step in learning OOP and this is the first problem I can not solve. The maximum number of maximum numbers in this class should be returned. I want to number the numbers in the private sector and in the public realm. But when I want to use variables from the Once you understand it, it should be clear that what you are doing is defining all that inside your class. C ++ allows you to create nest class / structure definitions so you can create martial parameters or return value structures. Avoid collision of namespace in these two result sections, database :: results and exam :: results instead of just "results". However - these are just definitions. They do not show - it does not affect the external class, it means that they are not being used to add a member to the class. Your code: Somehow declares "myclass :: data", but member of the class does not add "type" myclass :: data. Line "structure data =" is invalid, you are trying to hand over one type of values. This might be You only need the Q & amp; If you are going to reuse the structural definition outside the boundaries of the classroom, then in a structure, for example in derivative or parallel classes where you want to add more than one type of object You can probably do the following, but if you do this, then this will eventually kick you to interrupt yourself: There is a better way if this coupling of members will need to appear externally for some degree: This is a hyperactive for such a simple case, but C ++: Welcome to the boilerplate language. struct data {} in the public area, the compiler says that the variables are not declared. Please tell me why I found these errors
class myclass {private: // < - Not necessary, you have already said that by saying "class". Structure Data {// & lt; - This is the definition of "a class with the public:" Just here. ...}; };
class database {class result {...}; }; ... class results {class results {...}; };
class myclass {private: structure data {// & lt; - This is a TYPE declaration, struct myclass :: data int q; // int w; //}; // & lt; - There is no member's name here, so MacLeace does not affect itself Public: get zero (int a, int b) {struct data = {a, b}; // Here I want to pass the variable in the data stratum} int max () {// This function returns the largest number if (q> gt; w) return q; Second return; }};
class MyClass {int m_q; Int m_w; Public: zero set (full q, int w) {m_q = q; M_w = w; } Int max () const {returns (m_q> m_w)? M_q: m_w; // or # include & lt; Algorithm & gt; And back to std :: max (m_q, m_w); }};
class MyClass {Public: Stret Data {int m_q; Int m_w; }; Private: data m_data; Zero set (int q, int w) {m_data.m_q = q; M_data.m_w = w; } Int max () const {returns (m_data.m_q> m_data.m_w)? M_data.m_q: m_data.m_w; }};
No comments:
Post a Comment