Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Github: https://github.com/nezvers
- Youtube: https://www.youtube.com/channel/UCb4-Y0E6mmwjtawcitIAzKQ
- Twitter: https://twitter.com/NeZversStudio
- */
- #include <iostream>
- using namespace std;
- typedef struct MyStruct //to represent some object
- {
- int num;
- }MyStruct;
- class MyClass{
- public:
- MyClass() //how to do default constructor?
- {
- my_list = nullptr;
- }
- MyClass(MyStruct *_list[], int _size)
- {
- my_list = _list; //How to assign it right?
- for (int i = 0; i < _size; i++)
- {
- cout << my_list[i]->num << endl;
- }
- }
- ~MyClass(){} //Warning: deleting array - those are supposed to be deleted
- MyStruct **my_list; //How to declare it right?
- };
- int main()
- {
- MyStruct a,b,c,d;
- a = {1};
- b = {3};
- c = {5};
- d = {7};
- MyStruct *list[] = {&a, &b, &c, &d}; //holds pointers
- MyClass my_class(list, 4);
- return 0;
- }
Add Comment
Please, Sign In to add comment