Skip to main content

All Questions

Tagged with
-4 votes
1 answer
98 views

What functions can access a global variable that appears in the same file with them?

I asked ChatGPT and Google Bard a C++ question that "What functions can access a global variable that appears in the same file with them?" They answered that "Any function within the ...
MudassaRXaeed's user avatar
-2 votes
2 answers
83 views

How can I "globalize" struct methods?

I have a struct/class and i want to call some (or all) of its methods globally (without writing class_name::func_name() every time. I don't know what to replace on the using namespace foo; line. I ...
midi's user avatar
  • 7
0 votes
1 answer
72 views

Import of global variable failed C++

I have dll with a code: Dll.h: #ifndef EXPORT #define EXPORT __declspec(dllexport) #endif #ifndef IMPORT #define IMPORT __declspec(dllimport) #endif #include <iostream> #ifndef MY_GLOBALS_H #...
Ales100's user avatar
  • 165
-2 votes
2 answers
71 views

Global variables defined in Header. Other function call can see its changes

I have one .h file and two .cpp files: global_var.h fun.cpp main.cpp The details are shown below: global_var.h: extern int a; void fun(); fun.cpp #include <iostream> #...
pvasbob's user avatar
0 votes
2 answers
67 views

How to do this the right way? Declaring static object in function

The way I did it works, but feels like unbelievably bad programming. void draw_display() { static DISPLAY mydisplay = DISPLAY(parameters); mydisplay.set_orientation(0); do something with ...
Jnx's user avatar
  • 3
0 votes
0 answers
48 views

Are static class methods and variables visible form different modules (libs, dlls, exes)?

The case is quite simple - we had a discussion based on experiencing some linker issues, where colleagues of mine were stating, that we are unable to access the static methods and variables that are ...
CJ_Notned's user avatar
  • 288
-2 votes
3 answers
293 views

Are global variables actually global in their RAM share behavior? [closed]

In a multithreaded application, does each thread have its own copy of a given global variable for performance reasons, or can each thread only read/write into the same version? If the answer is the ...
Physician's user avatar
  • 483
-3 votes
1 answer
65 views

Why is there no difference in the two results between the global array and the local array?

I turned global arrays into local arrays in the main() function to solve my homework for C++. I expected the program to produce an error, but it outputs the same result without any error. What's the ...
SeoHyeon-Yi's user avatar
6 votes
1 answer
152 views

How to access the unnamed namespace with scope resolution?

I have this: #include <iostream> using namespace std; // Variable created inside namespace namespace first { int val = 500; } namespace { int val = 400; } // Global variable //int val ...
Johnz's user avatar
  • 75
-1 votes
1 answer
63 views

global function and class reference

I want to send integer value in class to global function from main. How should I send it as a parameter,I am sending the parameters wrong Tetris { private: int num; } printBoard(Tetris &t); ...
nwer's user avatar
  • 1
0 votes
2 answers
241 views

dynamically allocate matrix using build-in vector library

I am facing problem in allocating matrix using vector library globally. However, in my code, I am allocating vector as an array, which you can see below. matrix = new double*[row*col]; for (int i = 0;...
Arif's user avatar
  • 11
1 vote
2 answers
55 views

Global constant declared but cannot be used in given function for declaring array length [duplicate]

See line 91 of code, array<double,size1> poundData; //PROBLEM HERE array declared Global constant size1 can be used to represent integer value 5 everywhere else in code but returns an error if ...
finnh98's user avatar
  • 21
-2 votes
1 answer
122 views

c++ member function hides global function

This code snippet doesn't compile: struct M { int i; int j; }; void f(M& m) { m.i++; } struct N { M m; void f(int i) { f(m); // compilation error } }; clang says ...
Immanuel Kant's user avatar
1 vote
0 answers
309 views

Qt C++ How to create a global dynamic Object?

This problem has been bothering me for 2 days, I don't know how to implement it, thanks in advance I Have defined 3 class Equipment, Equipment1 and Equipment2. Equipment is the base class and the 3 ...
Xinhao Liu's user avatar
0 votes
0 answers
159 views

Contents of a vector get deleted after every loop iteration

I found out from another thread that apparently the objects defined within a specific iteration of a loop get deleted after the iteration is over. Hence I ran into a problem when I delete an element ...
Bentium's user avatar
  • 39

15 30 50 per page
1
2 3 4 5
24