c++

problem using enum in another cpp file

Hi I a have created a global.h file in which I define enum Token I get the garbage value of token if I use the value of Token other than glabal.cpp file I have also include the "global.h" file in other file where I am using the Token value how can I correct this problem. ...

C++ explicit template specialization of templated constructor of templated class

I have a class like template <class T> struct A{ template <class U> A(U u); }; I would like to write an explicit specialization of this for a declaration like A<int>::A(float); In the following test code, if I comment out the specialization, it compiles with g++. Otherwise, it says I have the wrong number of template parame...

what is the best way to use global variables in c++?

For me, I usually make a global class with all members static. All other classes will inherit from this global class. I wonder if this is a good practice? Anybody got any suggestions? ...

Why do I have to provide default ctor?

Why do I have to provide default ctor if I want to create an array of objects of my type? Thanks for answers ...

What is a Delphi version of the C++ header for the DVP7010B video card DLL?

I need help with converting c++ header file to delphi. I spent several days on this problem without success. Below is the original header file and my Delphi translation. C++ header #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifdef DVP7010BDLL_EXPORTS #define DVP7010BDLL_API __declspec(dllexport) #else #define DVP7010B...

How to keep unreachable code?

I'd like to write a function that would have some optional code to be executed or not depending on user settings. The function is cpu-intensive and having ifs in it would be slow since the branch predictor is not that good. My idea is making a copy in memory of the function and replace NOPs with a jump when I don't want to execute some ...

Handling minimisation in Fullscreen Win32 OpenGL

Hi, I'm trying to create a fullscreen application using Win32 and OpenGL. I change the resolution using EnumDisplaySettings and ChangeDisplaySettings and the OpenGL functions work fine. On its WndProc I handle WM_ACTIVATEAPP and detect when the user switched focus to another window, then I minimize the application's window. When the wind...

Normal C++ code in Qt doesnt build and run

Hello. I am using Qt under linux, if it matters. I ran successfully under Geany (a simple c++ compiler) the following: //my first program in C++ Hello World! #include <iostream> using namespace std; int main () {cout << "Hello World!"; return 0;} I opened Qt source file and copied the exact same code and i can't build or run. Thank...

array loop not working correctly? c++

Trying to count how many elements within the array are not equal to 0, is something set up wrong? I'd like to check all values in the array (it's a sudoku board) and then when all elements are "full" I need to return true. Is something off? bool boardFull(const Square board[BOARD_SIZE][BOARD_SIZE]) { int totalCount=0; for (int ...

In the following implementation of static_strlen, why are the & and parentheses around str necessary?

If I change the type to const char str[Len], I get the following error: error: no matching function for call to ‘static_strlen(const char [5])’ Am I correct that static_strlen expects an array of const char references? My understanding is that arrays are passed as pointers anyway, so what need is there for the elements to be reference...

delete a file in protected mode env(like windows xp)

hi I write a program to delete a file from somewhere of my harddisk in 8086 but when i use int 21h (ah=41h) an error happens and carry set to 1.and I cannot delete that. does anyone know what can I do? I think it should be from protected mode which does not allow my program to delete another file.I want the answer and language is not mat...

C++ write to front of file

I need to open a file as ofstream and write to the front of the file, while preserving the remaining contents of the file, which will be "moved". Similar to "prepend" a file. Is this possible using the STL or boost ? ...

Invalid use of 'void' in C++ when using struct and classes

I have 1 compiler error. It is from this line in my code: cout << myClass->Get_Type().discription; Where as Get_Type() is: void Tile::Get_Type() { return &myStruct; } I'm not quite sure what I am doing wrong. Or what for that matter could be going wrong. ...

how to copy char * into a string and vice-versa

If i pass a char * into a function. I want to then take that char * convert it to a std::string and once I get my result convert it back to char * from a std::string to show the result. I don't know how to do this for conversion ( I am not talking const char * but just char *) I am not sure how to manipulate the value of the pointer I...

Should every class have its own namespace?

Something that has been troubling me for a while: The current wisdom is that types should be kept in a namespace that only contains functions which are part of the type's non-member interface (see C++ Coding Standards Sutter and Alexandrescu or here) to prevent ADL pulling in unrelated definitions. Does this imply that all classes must...

Why might stable_sort be affecting my hashtable values?

I have defined a struct ABC to contain an int ID, string NAME, string LAST_NAME; My procedure is this: Read in a line from an input file. Parse each line into first name and last name and insert into the ABC struct. Also, the struct's ID is given by the number of the input line. Then, push_back the struct into a vector masterlist. I a...

How to combine ASCII text files, then encrypt, then decrypt, and put into a 'File' Class? C++

For example, if I have three ASCII files: file1.txt file2.txt file3.txt ...and I wanted to combine them into one encrypted file: database.txt Then in the application I would decrypt the database.txt and put each of the original files into a 'File' class on the heap: class File{ public: string getContents(); void setConten...

What native C++ profiling tool do you suggest?

Can anyone suggest a performance analysis tool that runs on win32 on a native c++ app? How about one that runs on Windows Mobile? Thank you. ...

How do I check if my program has data piped into it.

Im writing a program that should read input via stdin, so I have the following contruct. FILE *fp=stdin; But this just hangs if the user hasn't piped anything into the program, how can I check if the user is actually piping data into my program like gunzip -c file.gz |./a.out #should work ./a.out #should exit program with nice msg. ...

C or C++ Win32 How can I obtain the number of threads running in my program?

On Win32, how can a C++ program determine how many threads are active in my program's process? Is there an API call? ...