130 Solved Topics

Remove Filter
Member Avatar for triumphost

I have the following code for 2D dimensional arrays being flattened as 1D C-style arrays: #include <iostream> int main() { int width = 4, height = 10; int arr[width * height]; for (int i = 0, k = 0; i < height; ++i) { for (int j = 0; j …

Member Avatar for Banfa
0
996
Member Avatar for triumphost

Why is accessing data in an uninitialised array undefined behaviour? I ask because I was doing some benchmarking on `vector<int>` vs. `int*` vs. `int**`. My results were: http://stackoverflow.com/questions/20863478/class-using-stdvector-allocation-slower-than-pointer-allocation-by-a-lot Now I'm being told if I use the raw array and try to access an index without initialising it first, it is …

Member Avatar for mike_2000_17
0
193
Member Avatar for triumphost

Should I be using std::wstring or std::string and wchar_t or char? All this unicode stuff is confusing me. I want my application to work on both windows and linux without too many problems and changes but I'm considering unicode vs. ansi. Any ideas? I ask because I see many applications …

Member Avatar for vijayan121
0
1K
Member Avatar for triumphost

I want to use it because it says it supports all the C++11 features and I'm hoping that includes Regex as well since gcc isn't near finishing anytime soon.. However, many other websites are saying that clang requires Mingw/gcc to be used in the first place. It doesn't make any …

Member Avatar for triumphost
0
702
Member Avatar for triumphost

template<typename T> void Transpose(T** Data, std::size_t Size) { for (int I = 0; I < Size; ++I) { for (int J = 0; J < I; ++J) { std::swap(Data[I][J], Data[J][I]); } } } int main() { int A[4][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, …

Member Avatar for mike_2000_17
0
115
Member Avatar for triumphost

I'm trying to write a cout formatter that uses the comma operator and insertion operator. I wasn't able to get that to work so I decided to write it similar to std::boolalpha. when you use `std::boolalpha`, it is able to change 0 values to true and false and you can …

0
190
Member Avatar for triumphost

I wrote a large project dealing with images, files, and WINAPI functions. I decided to add RichTextEdit to it and used the msfedit.dll.. Turns out that it only supports UNICODE style strings and chars and my entire project is std::strings and LPCSTR's, etc.. None of the WINAPI functions are unicode …

Member Avatar for Ancient Dragon
0
214
Member Avatar for triumphost

Assuming a simple class like below and the main like below, will the class variable be stack/heap allocated depending on how the class is instantiated? OR will the class variable be allocated depending on how it is implemented? class Foo { private: std::string Bar; public: Foo() : Bar(std::string()) {} }; …

Member Avatar for mike_2000_17
0
17K
Member Avatar for triumphost

How can I install gcc 4.7.2 for codeblocks that supports both 32 and 64 compilation? If I install the x32 bit compiler: x32-4.7.2-release-win32-sjlj-rev10 it will compile with -m32 compiler switch but give a bunch of linker errors for -m64 If I install the x64 bit compiler: x64-4.7.2-release-win32-sjlj-rev10 it will compile …

Member Avatar for triumphost
0
383
Member Avatar for triumphost

I have a class called Control. All other "controls" inherit from this class. Some controls need a default constructor so that I can assign or construct them later. The classes look like: class Control { private: //All Members Here.. void Swap(Control &C); public: Control(DWORD dwExStyle, std::string Class, std::string Title, ....); …

Member Avatar for triumphost
0
845
Member Avatar for triumphost

Why do I need a static class member? What are the advantages and disadvantages of it? Is there any way that I can have non-static member fuction without doing anything outside of the class (such as passing an instance)? class Control { private: HMENU ID; HWND Handle, Parent; std::string Class, …

Member Avatar for Ancient Dragon
0
309
Member Avatar for triumphost

http://i.imgur.com/kWrBizl.png In the above Image, I generator a Sudoku Matrix of 9x9 values. Is there any way I can allow user to enter individual values by moving around the caret and typing? Basically, I want them to just be able to change the values displayed on the screen by moving …

Member Avatar for tinstaafl
0
173
Member Avatar for triumphost

How can I calculate CLOCKS_PER_SEC.. It is defined as 1000 in ctime. I don't want it defined. I want to calculate the actual value.. I tried the below code but it seems to be giving me my CPU speed.. on a 2.8 Ghz processor, it prints 2800. On a 2.0 …

Member Avatar for deceptikon
0
2K
Member Avatar for triumphost

Can C++11's Mutexes be used for Inter-Process Communication? In other words, can it be used for shared memory and signalling an event? Currently, I'm using CreateEvent and SetEvent from WINAPI and I wanted a cross-platform way of doing so without doing #ifdef windows and ifdef linux, etc.. I use CreateEvent …

Member Avatar for vijayan121
0
6K
Member Avatar for triumphost

I'm diving into various Image reading and writing methods and writing my own. I decided to tackle TGA/Targa. I got reading working flawlessly. It reads both compressed and decompressed .TGA files. I got writing decompressed .TGA files working. However, I cannot figure out how to write Compressed .TGA files. I …

Member Avatar for triumphost
0
1K
Member Avatar for triumphost

This may be a long post but I really need to know how to Convert between the two image formats and amonst themselves as well. Here goes: I have a struct like the one below that holds all pixel information: typedef union RGB { uint32_t Color; struct { unsigned char …

0
338
Member Avatar for triumphost

I'm in a bit of a dilemma. I want to know what the difference is between Foo and Meh. I wrote both of them and I did not like Foo so I wrote Meh. They both work but is there an overhead to Meh? Is there anything bad about Meh? …

Member Avatar for mike_2000_17
0
228
Member Avatar for triumphost

Ok I know the difference between delete and delete[] BUT this question just all of a sudden popped in my head since "NOTHING" happens when I use delete[] for all purposes. Now I know when to use one or the other but it still for some odd reason bothers me …

Member Avatar for mitrmkar
0
179
Member Avatar for triumphost

I'm trying to flip an image which has its pixels stored in a vector. For some reason, when I try to flip it, the image gets distorted and gray/fuzzy. Any idea why? My code is as follows: void JNIData::FlipBytes(void*& Result, bool TopDown) { unsigned char* Pixels = &BufferPixels[0]; //vector of …

Member Avatar for mike_2000_17
0
227
Member Avatar for triumphost

I have a void pointer that I casted to a char*. I'm trying to put different data types in that char* without having to cast so much. This includes doubles, floats, int's, etc.. char* Data = static_cast<char*>(GivenPtr); switch(reinterpret_cast<int>(Data)[0]) //Or should it be reinterpret_cast<int>(Data[0]) { case OBJECT: //defined as 301; { …

Member Avatar for triumphost
0
155
Member Avatar for triumphost

Does anyone have a tutorial for writing Custom Allocators and Memory Pools for std::vectors and Objects? Basically I've looked at placement new and I want to know how I can force vectors to use this with my shared memory pointers. I'm thinking writing a class for it might be much …

Member Avatar for mike_2000_17
0
756
Member Avatar for triumphost

I had absolutely no clue where to post this but I figured since it crashes on the C++ side, I'd ask here. I have the following code: Java side (Loads My C++ DLL just fine.. Passes it a ByteBuffer so that I can write to that): import java.io.IOException; import java.awt.*; …

Member Avatar for triumphost
0
400
Member Avatar for triumphost

How can I figure out where words intersect in the following? AAAA#BBBB .#.##C##H .#.##D##I .#...E.#J ##.##F##K ###..G..L '#' represents the black spots in a crossword where you cannot fill in. '.' represents the spots with missing letters that need to be filled in. I've read the puzzle into a vector<string> …

Member Avatar for deceptikon
0
426
Member Avatar for triumphost

Why is C++ on linux basically C? I've tried everything to avoid C on linux but it's simply near impossible. I've tried to stick directly to the standard library but I somehow find myself using dirent.h, types.h, etc.. Is there any other ways to do these other than using C …

Member Avatar for deceptikon
0
763
Member Avatar for triumphost

I'm learning several languages. 5 at once but I took a liking to one specific feature of java. The This keyword. From their tutorial: /*Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You …

Member Avatar for mike_2000_17
0
493
Member Avatar for triumphost

Is there a way to do the following better? Current I write a set of pixels to a file called "PngFile.bmp". Then I read that file back in as a PNG encoded buffer.. Then I save that buffer back to the harddisk and delete "PngFile.bmp" /*std::fstream PngFile(TempPath, std::fstream::out | std::fstream::app …

Member Avatar for triumphost
0
2K
Member Avatar for triumphost

So I've started learning makefiles today for a project I've been working on. The project uses OpenGL and GDI. I decided to dive right into make files and so far, everything compiles but at the very end, it gives a bunch of undefined references. Thing is, when compiled in codeblocks, …

Member Avatar for vijayan121
0
2K
Member Avatar for triumphost

I've been trying to do this for some time. I can do it with a vector but with a const void*, it crashes badly! My bad code: Bitmaps::Bitmaps(const void* Pointer, int Width, int Height, uint32_t BitsPerPixel) { Pixels.clear(); memset(&Info, 0, sizeof(BITMAPINFO)); width = Width; height = Height; size = ((width …

Member Avatar for triumphost
0
187
Member Avatar for triumphost

I keep getting "None of the 6 overloads could convert all arguments". I only get this problem in visual studio though. When I compile with g++ or codeblocks, it works perfectly fine. The code I'm calling my templates with is: `MemDeSerialize(ListOfItems, SerializedData, size_t(Data[2]));` The definitions: template<typename T> void MemDeSerialize(T& Destination, …

Member Avatar for mike_2000_17
0
186
Member Avatar for triumphost

What are some safe sized datatypes? Inother words, stuff like size_t, uint32_t. They don't seem to change no matter what machine I use. I'm asking because the confusion comes in here: I'm not sure when to use long vs int. I did a sizeof(int) and sizeof(long) and they are both …

Member Avatar for deceptikon
0
161
Member Avatar for triumphost

I currently use this to serialize data, write it to shared memory so that another program can reconstruct it and use it: template<typename T> void Serialize(unsigned char* &Destination, const T &Source) { CopyMemory(Destination, &Source, sizeof(T)); //Destination += sizeof(T); //Not sure if to add this or not. } template<typename T> void …

Member Avatar for triumphost
0
106
Member Avatar for triumphost

Hey guys, I have two structs and I have two functions in two DLL's. DLL-A is attached to a process and collects data. When the data is requested by DLLB which is attached to a second process, DLLA maps the data for B to read. The problem is, I cannot …

Member Avatar for triumphost
0
955
Member Avatar for triumphost

Hey all. I'm having a problem with a DLL being loaded. In codeblocks, if I don't export Main + ALL the functions in my DLL, they cannot be used by an external program! Yet in visual studio, I exported nothing and external programs are able to load the DLL. Example: …

Member Avatar for triumphost
0
527
Member Avatar for triumphost

How can I iterate a buffer with a stride? For example, I saved the pointer to a vertex buffer for later use. I've got the stride, the pointer, and triangle count for vertices. I want to iterate my pointer using this info to get the vertices. I'm doing it wrong …

Member Avatar for triumphost
0
312
Member Avatar for triumphost

What are the last 4 values for? (m[0], m[4], m[8], m[12]) (m[1], m[5], m[9], m[13]) (m[2], m[6], m[10], m[14]) (m[3], m[7], m[11], m[15]) I've looked everywhere and cannot figure out what m[3], m[7], m[11], m[16] are for (ModelView Matrix).. It says to ignore them but I can't just ignore them …

Member Avatar for mike_2000_17
0
161
Member Avatar for triumphost

How can I compare Dimensional arrays using iterators? My attempt is below but I gave up and used indexing instead. I plan to change comparing doubles with == to use epsilon later. Also should I be using vector of vectors? //In my class, Data is defined as std::vector<std::vector<double>> Data; bool …

Member Avatar for deceptikon
0
186
Member Avatar for triumphost

In OpenGL, I'm reading about glVertexPointer which has a parameter: `const void* pointer` and it is a pointer to the coordinates of the first vertex. Thing is, it doesn't have any parameters that tell you the amount of vertices there are. I'm wondering if there is a way to copy …

Member Avatar for triumphost
0
214
Member Avatar for triumphost

I hooked a game's OpenGL.dll with my own glwrapper but this game uses two dll's.. It uses a wrapper of OpenGL32 and my hook is also a wrapper. So what I need: I want to know if these symbols point to the same functions.. http://i.imgur.com/eMZC5.png @28, @28, @28.. That means …

Member Avatar for gusano79
0
136
Member Avatar for triumphost

So... I'm looking into learning Assembly. I downloaded the FASM assembler and I want to know how useful is assembly? I want the opinion from Cpp programmers because assembly programmers always tell me it's the best language -__- Also quick question: How do I know which register to put stuff …

Member Avatar for DeanMSands3
0
166
Member Avatar for triumphost

How can I get SetConsoleTextAttribute to work with my Console? I tried everything. First I redirected the cout and cin buffers so that my console can have input and output. But now it doesn't have Colour :S I used: HANDLE OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(OutputHandle, 10); I don't think GetStdHandle is …

Member Avatar for triumphost
0
338
Member Avatar for triumphost

How can I create PNG Files from an array of bytes or read a PNG file to create an array of bytes? I looked up the format but it looks nothing like a bitmap and I read the GDI doesn't support PNG's. So how does LibPNG do it then? I …

Member Avatar for DeanMSands3
0
310
Member Avatar for triumphost

I'm learning how to detour-hook functions from tutorials online but when I follow along, my DLL says symbols not found. The error I get says: > Linking dynamic library: bin\Debug\GLHook.dll > Cannot export GLHook_glAccum: symbol not defined > Cannot export GLHook_glAlphaFunc: symbol not defined I don't know why though.. I've …

Member Avatar for triumphost
0
761
Member Avatar for triumphost

I'm having a huge problem trying to learn how to export classes from a DLL. I can do some functions just fine but the classes are mangled :S I've tried from .def file, I've used extern "C" but when I did, it threw errors and won't export the class at …

Member Avatar for mike_2000_17
0
2K
Member Avatar for triumphost

I have: 39H4-GTT7-LGLN And I'm trying to find every possible combination of sets. Basically each section is scrambled within itself. So there's only 16 combinations for each section. Example the first section I wrote it out as: 39H4 394H 349H 34H9 49H3 4H93 493H 4H39 9H34 934H 943H 9H43 H493 …

Member Avatar for Lucaci Andrew
0
107
Member Avatar for triumphost

I have a Two Test classes that use variadic templates but I made the constructors explicit so that the compiler doesn't convert anything and leave everything as it was. One class was Array and the other was called 2DArray. When I intialize 2DArray, the compiler was converting its arguments to …

Member Avatar for deceptikon
0
3K
Member Avatar for triumphost

I'm trying to test my copy con and move con as well as their assignment operators. It NEVER gets invoked :S Copy con gets invoked just fine but the assignment operators are never called and neither is the move constructor. How can I test it to make sure it works …

Member Avatar for mike_2000_17
0
276
Member Avatar for triumphost

> "warning: 'class Debug' has pointer data members but does not override 'Debug(const Debug&)' or 'operator=(const Debug&)' [-Weffc++]" The only pointer member I see here is the HANDLE hTHread. Why should I override my constructors or add a move/copy to this class as the compiler suggests? class Debug { private: …

Member Avatar for mike_2000_17
0
4K
Member Avatar for triumphost

How can I create a Modifiable Const vector but make it unable to be resized? Either that OR I want to return a pointer from a function but not allow the user to delete it. This is my example so far: class MemberRawArrayVector { private: vector<unsigned char> MemberRawArray; public: MemberRawArrayVector(int …

Member Avatar for mike_2000_17
0
216
Member Avatar for triumphost

Why does the following code skip the initialization of values of the temporary created? Box::Box() : X1(0), Y1(0), X2(0), Y2(0), W((X2 < 0 ? -X2 : X2) - (X1 < 0 ? -X1 : X1)), H((Y2 < 0 ? -Y2 : Y2) - (Y1 < 0 ? -Y1 : Y1)) …

Member Avatar for Milton Neal
0
231
Member Avatar for triumphost

I'm a bit confused atm, I don't know when to use const T& or T& or T as a parameter. Currently I'm doing: void Resize(std::vector<T> &Vec, const size_t &NewLength) //Ahh edited the function as a result of Lucaci's answer. { Vec.resize(NewLength); } //But thinking of doing: void Resize(std::vector<T> &Vec, size_t …

Member Avatar for mike_2000_17
0
3K

The End.