I want to call the structure declared in class private in C++ in the main function

Asked 2 years ago, Updated 2 years ago, 79 views

In the header file, a class named Student has been declared and a structure named collector has been declared in private. I want to make one more cpp file and then make an electro structure in the private part of the main function and use it, but I don't know what to do. It's my first time using the site, so I'll take it with thanks if there's anything I'm not familiar

class c++

2022-09-20 19:28

1 Answers

I hope the immature answer will be helpful.

main.cpp

#include <iostream>
#include "head.h" //Include here.
using namespace std;

int main() {
    Student st;
    st.setInit();
    st.coutLecture();
    return 1;
}

head.h

#pragmaence

class Student {
private:
    struct { int x; int y; }lecture;
public:
    void setInit() {
        this->lecture.x = 3;
        this->lecture.y = 6;
    }

    void coutLecture() {
        std::cout << this->lecture.x << "," << this->lecture.y << "\n";
    }
};


2022-09-20 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.