M
M
Muriam2019-03-23 17:36:58
C++ / C#
Muriam, 2019-03-23 17:36:58

What are macros in C++?

Why is the result of this expression = 3 and not 9 ?
5c964473939f7183345090.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2019-03-23
@Muriam

because x is 3 + 0; (whole) this is the stupid text that will be inserted instead of x ;
x * x == 3 + 0 * 3 + 0 ;
we get
3 + ( 0 * 3 ) + 0;
3+0+0;
3;
Atavism
is sometimes useful
https://en.cppreference.com/w/cpp/preprocessor/replace
and so there is at least
https://en.cppreference.com/w/cpp/language/constexpr
https://en.cppreference .com/w/cpp/language/templates

code
#include <iostream>

template<typename T>
auto sqr = [](T x)
{
  return x * x;
};

int main()
{
  std::cout << sqr<int>(3 + 0);
}

что будет развернуто в что-то типа
//...
class __lambda_3_12
{
  public: inline int operator()(int x) const
  {
    return x * x;
  }
//...
};
//...

A
AtomKrieg, 2016-12-16
@AtomKrieg

def get_hel(self):
    return self.hels

Also look on YouTube about getters and setters in python.

S
Stepan Krapivin, 2016-12-16
@xevin

It doesn't work because the called get_hel() method is trying to return a non-existent attribute self.get_hels
Most likely this is a typo and get_hel() should return self.hels

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question