Похожие чаты

What if non-static variable is returned from static function? Will

it be allowed? If no, then why?

6 ответов

7 просмотров

A static function is one, that is only available within in translation unit. The static of the function have nothing to with the static storage class. If you are using C++, then you have additionally static function within classes, which means for them to be accessible without an object of that class.

Questions like these which you can easily check by running it should be asked after you've tried it yourself. Make it a habit of testing things yourself first. Make your own conclusions and come here (with your the test code) to verify it, don't be lazy.

12-Nothing Автор вопроса
Manav | avoid unnecessary messaging me
Questions like these which you can easily check by...

I did but I could not understand why non static members cant be used inside the static function

12 Nothing
I did but I could not understand why non static me...

See this class MyClass { static int a = 0; int b = 2; public: static int staticfn() { return a+b; } }; This code is wrong. Why? Because the static member function is not called through an instance. It's done this way instead: MyClass::staticfn(); but then if called this way, what is b? How can the function know about b if we aren't calling it through an instance?

12 Nothing
I did but I could not understand why non static me...

Member variable is accessible when the class is initialized. A static function could be called without class initialization.

Похожие вопросы

Обсуждают сегодня

@LGCYMan @JustinKKW Q/A List 1. this part confuses me on #8: "From there, a bridge between erc20 LGXY and erc20 LGXY will be out once that swap is closed." does this mean ...
Sig | LGCY | BattleVerse L1 | BitWin
1
Did @Beeker really get banned? That's ridiculous. He's one of the few left here with half a brain and you might not always like his narrative @dgb_ycagel , but he often keeps ...
Leroy Gerrits
1
async login(req: Request, res: Response, next: NextFunction): Promise<void> { try { const { errors, input } = await RequestValidator(LoginRequest, req.body...
. .
1
Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
Привет, нужен совет старших товарищей. Есть глобальная переменная var DefaultDataFolder:string; инициализируем DefaultDataFolder:='a:\_OUT\'; есть примитивная процедур...
Max Otto
14
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
46
We heading to 1.1$ 🤔?
CryptoBo$$
35
Вопрос. Теоретический. Есть список команд. Команды отправляю в обработку некой функции, по очереди. Разные команды могут давать разные результаты после обработки. В зависимос...
Serjone
7
Agreed. And on a lighter note, I just love the idea of earning $FunToken while having fun. It’s like getting paid to do what we love. Who wouldn’t want that? 😄
SpaceGemz
13
у меня немного странная проблема причину которой я никак не могу понять.. что не делаю, даже если я с гитхаба скачаю чистый кловер у меня остаются старые бут арги и я не мог...
Σοφία ✨🐾
5
Карта сайта