Похожие чаты

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

it be allowed? If no, then why?

6 ответов

26 просмотров

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.

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта