Questions tagged as 'c++'

1
answer

Overloading the operator =

I'm performing the operator overload = for a Rational data type. That is, for this to work with the Rational type: res = p; According to the book I am following, it tells me to do it with the operator = as a member function (method) and:...
asked by 09.02.2018 / 11:51
0
answers

Texture in Sphere with Open GL

I'm trying to put a texture in a quadric object of glut in c ++ but for some reason I'm putting the texture in the background, I'm new with glut, if someone could help me. void drawScene(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFE...
asked by 03.03.2017 / 01:09
3
answers

Difference in parentheses while with return

Why can I do this: return (tarea->ini == NULL) && (tarea->fin == NULL); // no hay parentesis global but not while (tarea->ini != NULL) && (tarea->ini != kol) // no hay parentesis global ? since it tells me...
asked by 20.03.2018 / 04:12
3
answers

Show zeros to the left of an integer in C ++

Hi, I have a 4-digit integer, which sometimes for example, will be vetted, sometimes it will have zeros to its left, but the problem is that I do not know how to show the leading zeros. Let's suppose that I have the following integer: 0382...
asked by 11.03.2017 / 19:03
1
answer

C ++: std: endl VS \ n

I understand that the only difference between the two ways of making a new line is that the first one also empties the output buffer. Could you show me a practical example where you can see the difference in using one and the other?     
asked by 24.06.2016 / 19:27
1
answer

Using std :: less with std :: function

I'm trying to meter std::function< > into a std::set< > . For this, we need a function that compares the values entered. As std::function does not provide any comparison operator, I thought about this: #inc...
asked by 08.01.2018 / 15:34
2
answers

C / C ++ - Pointers (Heap and Stack)

A few weeks ago I did a question about pointers . Now I have another that I believe involves the Heap and the Stack. The code is as follows: int main() { int *x; int *y; int w; x = new int(); w = 85; *x = w; y =...
asked by 15.01.2018 / 15:23
2
answers

Templates for different data in C ++

I'm using templates in C ++ and I'm new to this, so I do not quite understand how to "reuse" functions regardless of the type of data. I have the code shown below: template<typename T> const T &min(const T &a, const T &b)...
asked by 25.05.2018 / 12:43
2
answers

Is it correct to use the same array as input and output in sprintf?

I found the following code: char query[255]; sprintf(query, "SELECT NOMBRE, "); switch (tipo) { case TIPO_1: sprintf(query, "%s ID", query); break; case TIPO_2: sprintf(query, "%s APELLIDO", query); brea...
asked by 13.01.2016 / 16:02
2
answers

Slow reading cin

By default the reading with cin is desperately slow compared to its counterpart scanf ... when logic tells us that it should not be like this: With cin a direct call is made to the function that knows what the type of th...
asked by 22.06.2017 / 10:36