Questions tagged as 'c++'

1
answer

What is the best way to store a reference in an object?

Suppose I want to create a library where an object should receive another object added by the user and store for later use. Ex: //header.h class Caixa{ private: Botao botoes[5]; public: void addBotao(Botao botao){ int i; whil...
asked by 21.11.2015 / 13:53
1
answer

Why use const after the function?

I noticed in some code from other C ++ programmers that use functions like: bool CClass::isRunning() const { return this->_running; } I understand that in this way it is not possible to modify any member of the class, only serves for...
asked by 16.01.2017 / 20:11
1
answer

Does a char type always have size 1?

I've always known that char is the only type that has fixed size by specification. Its size is 1, no matter the architecture. But I came across sizeof('a') returning 4 rather than 1. Like this? Did I Learn Wrong?     
asked by 19.01.2017 / 11:18
1
answer

Why have so many parentheses in macro?

Seeing this intrigues you because you need those parentheses that seem unnecessary. What is their functionality? #define SUB(x, y) ((x) * (y))     
asked by 23.03.2017 / 11:37
1
answer

How does printf work?

How does the code behind the function printf() of C work? I know what this function does, I want to know how it works.     
asked by 04.08.2015 / 21:51
1
answer

How to "call" a function from a Lua table in C ++

I'm trying to "call" a function from a table written in Lua . The problem is that I am not able to pass three arguments to this function. When I pass the arguments, it is as if the Lua skips the first argument and continue...
asked by 26.08.2014 / 20:20
1
answer

What is a shared_ptr?

If possible, with a code example, as this is missing from the reference to really understand when and how to use shared_ptr .     
asked by 16.02.2016 / 17:23
1
answer

Reduce a string in C language

How do I reduce the size of a string in C? In my program it is implemented as follows: char nomeString[] = "nomedoarquivo.txt"; I want to cut the ".txt" from the end of the string .     
asked by 27.11.2016 / 17:42
1
answer

Is it interesting to create a type just for a pointer to a type?

I've seen it doing a MinhaEstrutura * be explicitly typed as typedef MinhaEstrutura * pMinhaEstrutura; Why not always do this and get rid of having to rename?     
asked by 12.01.2017 / 11:16
1
answer

Is it correct, following object orientation, to use pointers for C ++ functions?

I'm creating classes that represent items in a menu, each item executes an action and I'm assigning the action by a function pointer to each instanced menu item, is this valid following POO? or is there an easier and more practical way to do it?...
asked by 15.10.2016 / 04:35