R
R
r1mple2020-06-23 02:55:49
C++ / C#
r1mple, 2020-06-23 02:55:49

How to access a class parameter?

3 am, I can't take it anymore, I'm tired.
We need to make a program, and so it turns out that we need it on the pluses.
class A(object):
def __init__(self, b):
self.b = b
a = A(1)
print(ab)
This is how easy it is for me to access class parameters.

I need the same, only on the pluses.
===========================
Header:
#pragma once

class Window
{
public:
Window(char* fileName);
voidMaximizeWindow();
};
============================
The class itself:
#include "Window.h"
#include

Window::Window(char* fileName) {
fileName = fileName;
}
void Window::MaximizeWindow() {
Get the value of the Window class parameter here
}
============================

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris the Animal, 2020-06-23
@r1mple

You can access a class field like this:

#pragma once
#include <string>

class Window
{
public:
  Window(const std::string& fileName);
  void MaximizeWindow();

private:
    std::string _fileName;
};

#include "Window.h"

Window::Window(const std::string& fileName)
    : _fileName(fileName) {

}

void Window::MaximizeWindow() {
    // Здесь можно обратиться к полю _fileName
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question