how to get the function access the other .cpps variables? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I tried to create a small application to get used to fileI/O but I don't know how to get the load()-function in Functions.h to overwrite to variables in main.cpp with the ones in Functions.h
I save the variables from the main.cpp by using them as parameters in a function.
All fine so far
But when I call the load()-function in the main.cpp it loads the variables from the file and stores them in Functions.h
i could do
var = Functions.var;
everytime but as this programm is controlled by the user i need a way to do what I wrote above inside of the load()-function.
I hope you understand my problem and may be able to help
im sorry if a similar question was already answered but I didn't find anything helpful when searching but maybe this was just due to me not knowing what to search for

It's a bad design if a load function knows too much about other variables. Instead, you should use a function argument. Pass the variable that you want loaded to the load function. That does mean that you need a reference parameter:
void load(std::string& var) { ... }

Related

namespace "Detours" has no member "uint8_t" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have been trying to create a dll program for a game called csgo. But my main problem is that it wont work until I have fixed this bug.
<namespace "Detours" has no member "uint8_t">
It happend right here:
oEndScene = (EndScene)Detours::X86::DetourFunction((Detours::uint8_t*)d3d9Device[42], (Detours::uint8_t*)hkEndScene);
Detour namespace doesn't define a uint8_t type (since it is from Microsoft, I think they'll name it something like USHORT). It is available in the STL in the global namespace. So to resolve this, dont specify where (which namespace) the type comes from,
oEndScene = (EndScene)Detours::X86::DetourFunction((uint8_t*)d3d9Device[42], (uint8_t*)hkEndScene);
And make sure to include stdint.h or inttypes.h header file to get the type.
Additional: Use reinterpret_cast<uint8_t*>() instead of (uint8_t*).
Add
#include <cstdint>
then remove the "Detours" part of "Detours::uint8_t". Just use the regular uint8_t, I don't think you need the wrapper.

Bindind to keys C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Hello there I am a realative newbie when it comes to using different "commands" in order to achieve things so I was wondering if any of you know a way to bind a key to do a certain task anywhere in the programme ,so I would be able to display a function for example and after the display finishes the programme carries on normally like nothing happened and then that same key on any other push would still do the display . Thanks in advance
Plain C++ does not have any concept of "key binding". The platform (e.g., the operating system) has this knowledge and it provides some libraries to handle it. So, you must provide more information about the operating system, or use a cross-platform library like Qt.

return this-> command in C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
return this->
what is that mean in C++
..
using namespace std;
IOM ConfigurationManager::getIOM(int iomId) {
return this->IOMs[iomId];
..
the relevant part of the whole code is above.
The code that I wrote is from a huge project which was waiting for someone to finish. I am not good at C++ but I need to learn more not to lose that job. Anyway, the project is full of "return this->...." which I thought unnecessary, that's why I asked is there smt special that we should use that notation
This piece of code simply means that the IOM at index iomId in the IOMs array in the ConfigurationManager object is returned. Note that the this->IOMs is the same as IOMs in this case, thus it seems the this is only there for clarity.
this is a pointer to the current object. The -> operator allow you to access a member inside a pointer to an object.
Thus return this->IOMs[iomID] returns the IOM object in the current ConfigurationManager at index iomID.

How to use a header file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am switching from PHP to C++ and I have this questions.
I have
main.cpp,true.cpp,false.cpp and header.h.
The header.h has a function "Function_go_to_requested_page.cpp()"
main.cpp looks like this
#include header.h
bool x;
cin>>x;
Function_go_to_requested_page(x) // It should take to page true.cpp if x=1 else to false.cpp
I don`t know how to define this function in header file,as I will be calling this function in both in true.cpp and false.cpp .
Thanks for your time.
how to link header files in c++
This might shed some light on how to do it. Header files essentially define what's going to be in a .cpp file. I would get a book this is pretty basic stuff.

Adding multiple data types to the same variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am relatively new to programming, and I can only really understand C++. I have recently started working on a project that requires the user to input something that will allow them to make a selection. I can't figure out how to make it possible for the user to input a string or a char but get the same result. I know that this would require that I assign the variable that the user inputs (for example 'a') two data types, but how do I do that? I've tried using "string/char a;" but that doesn't work.
Could someone please help me with multi-data-type variables?
Thanks
The string type will work for all user input. Since it "doesn't work" for you, we can't help you further if you don't show us what you tried.
If the User is the one making the Input from the I/O, then you get to decide if you will treat the input as a string or char. After receiving the Input you should know what you want to do with it. And you can also store the input data in array, vectors or list. Primitive data types can do so many things just understand the purpose and function of your program.