130 Solved Topics
Remove Filter I have the following code to take a bitmap of a portion of the screen specified by the Box Area. Area is just a struct that holds Width, Height, X1, Y1, X2, Y2 and represents a box. Basically a RECT with additional features. For some reason, if Box is (0, … | |
I've just read a tutorial on Classes Under the hood/behind the scenes. It says that: Foo* A = new Foo(); // Is different from: Foo* B = new Foo; What in the world? I never put the brackets for my classes like that. Why does the first initialize variables and … | |
I just learned C++ style casting and the 4 types of casts. I'm not sure if I'm abusing it though. Examples: typedef long (*stringFromString)(int, char*) __cdecl; //TO: typedef long static_cast<*stringFromString>((int, char*)) __cdecl; SmartSetup((char*)World.c_str(), (char*)",f5", 765, 503,(char*)""); //TO: SmartSetup(static_cast<char*>(World.c_str()), static_cast<char*>(",f5"), 765, 503, static_cast<char*>("")); memcpy(&INH, (void*)((DWORD)Buffer + IDH.e_lfanew), sizeof(INH)); TO: memcpy(&INH, static_cast<void*>(static_cast<DWORD>(Buffer) … | |
I have just came across a class for the first time ever that does not have variables in any of it's declarations but has them in the implementation. Why is this class behaviour allowed? What are the benefits of not putting variable names? class Testing { public: Testing(int, int, int); … | |
This works fine. For any type I create (Example): BoxArray& operator -= (const Box& B); BoxArray& operator -= (const BoxArray& BA); BUT when it comes to my literal types like char's and strings and char*'s, I get Ambiguous overloads: StringArray& operator -= (const std::string& S); StringArray& operator -= (const StringArray& … | |
Hey when I don't template my classes, I can pass member functions to eachother normally. But when I template it, I get errors. The two functions are defined as so: CustomType& Delete(int Position); CustomType& Delete(T ValueToDelete, bool All = false); CustomType& Delete(CustomType ValuesToDelete); And Implemented like this: template<typename T> CustomType<T>& … | |
How can I do the following but easier? I'm templating a class but I want it so that if typename T is of a literal type such as a string or char, then it can use the following member-function. If not then it cannot use it. I've been using typeid … | |
I've read that anonymous structs are a compiler extension and codeblocks allows them as long as -pedantic-errors are not enabled. My question is, since it is not legal in C++, what would be the legal equivalent of: typedef union XYZ { int Color; struct { BYTE X, Y, Z; }; … | |
How can I cast a class to another type? Example: class Point { Point(int X, int Y); }; Point A(10, 10); POINT P = (POINT)A; A = (Point)P; //I've tried: Point::Point(POINT P) : X(P.x), Y(P.y), Color(0) {} //Constructor. Point& Point::operator ()(POINT P) { if (X != P.x && Y != … | |
Well I like to learn as much code as I can in a day and I just came across the copy constructor. I do not understand when I need to use it. Do I need to use it for every class I make? I came across it after getting the … | |
Yesterday I took a dive into smart pointers and wasn't sure when I should use them vs. Raw pointers. I found out they are quite useful but they do not work all the time for me. Example of working: char* Buffer = new char[1024]; fread(buffer, 1, sizeof(buffer), infile); //took out … | |
Why does this say shaddowing? If I change my member X and Y to `_X, _Y` then when I access my class via the dot operator, it shows FOUR values.. Current Class: class Point { public: int X, Y; Point(int X, int Y); ~Point(); }; Point::Point(int X, int Y) : … | |
Currently I'm reading Multi-String values from the registry. These strings are double null terminated and single null delimiters are between each one. So below I have the following where these are declared as so: std::string KeyToRead, Result; DWORD KeyType. Now I'm returning an std::string aka Result. So I iterated my … | |
Why does the below crash? My pointer is still alive and is constructed in the main so it should not die until main returns :S I was using this with createthread a while back but my Mingw4.5 never supported it. I just upgraded to 4.7 but now this crashes and … | |
I have a header file that I include into my main.cpp file. I want to set some flags when this file is included. std::cout.flags(std::ios::boolalpha); I want to set that automatically how can I do this? I tried: #ifdef DEFINES_HPP_INCLUDED std::cout.flags(std::ios::boolalpha); #endif //Gives me the error: //error: 'cout' in namespace 'std' … | |
I'm trying to understand recursion and stack overflows. First, why does this not cause a stack overflow? Is it because the function returns every time and that the stack isn't populated upon each call? void Meh() { } int main() { while (true) Meh(); } Two, What is the difference … | |
The code below gives me a Narrowing conversion from int to uint32_t: typedef union RGB { uint32_t Color; struct { unsigned char B, G, R, A; }; } *PRGB; inline RGB Rgb(int R, int G, int B) {RGB Result = {((R & 255) << 16) | ((G & 255) << … | |
Can anyone check my memory class and suggest changes or things I may need? I'm writing it so that I don't have to worry about deleting anything everytime I allocate. #include <iostream> template<typename T> class Memory { private: size_t size; T* data; public: explicit Memory(size_t Size) : size(Size), data(new T[Size]){} … | |
What's a fast way to fill a union/struct of integral members with ALL Zeroes? RECORD* UNION = {0}; void ZeroStruct(int X, int Y) { UNION = new RECORD[X * Y]; int K = 0; for (int I = 0; I < X; I++) for (int J = 0; J < … | |
Is it possible to overload one operator more than once? I have a struct that is just my idea of a C++ Box. I'm trying to increase the size of a box using an integer or another box. I'm trying to do: Box X(0, 0, 0, 0); Box Y(1, 1, … | |
I have a union defined as so: typedef union RGB { unsigned Color; struct { unsigned char B, G, R, A; }; } *PRGB; I'm reading 32 bit and 24 bit bitmaps. I'm trying to Read Pixels from my RGB union and set pixels as well. I know bitmaps are … | |
I'm trying to have my function return an OPENFILENAME struct. Problem: It returns it fine and everything except that I cannot print the filetitle :S At the moment, it prints the path of the file perfectly fine but when it comes to printing the file title via cout, it prints … | |
Is it necessary to seperate the headers from the source? For example I don't know why but I love to do: //Foo.H class Foo { Foo(){} ~Foo(){} void Func() { //......... //......... } void Func2() { //........ //........ } }; Instead of doing: //Foo.H class Foo { Foo(); ~Foo(); void … | |
Currently I use: DWORD ThreadProc(LPVOID lpParameter) { void (* function)() = (void (*)())lpParameter; function(); return 0; } void Threading(HANDLE &hThread, DWORD &ThreadID, void* FunctionToPass) { hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (void*)FunctionToPass, 0, &ThreadID); } And I want to call it like: Handle hThread; DWORD ThreadID; Threading(hThread, ThreadID, AnyFunctionHere); That way … | |
I want to start developing an IDE or at least a Syntax highlighter into my program. Atm it's a simple text editor with basic copy paste functions. How does Notepad++ do it? Is there a way I can integrate that into my own program? If not then I'll write it … | |
I'm trying to convert My Console classes to .Net classes because I can't use std::vector or anything like that in WindowsFormsApplications. So I decided to convert all Vectors to Lists and I thought that the classes work the same but my code below throws a massive amount of errors and … | |
What is the difference between these two and why does one compile fine compared to the other :S //MyFile.h #include<iostream> using namespace std; inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb) { Str<<"R: "<<(int)Rgb.R<<" G: "<<(int)Rgb.G<<" B: "<<(int)Rgb.B; return Str; } //Main.cpp #include <iostream> #include "MyFile.h" using namespace std; … | |
I have the following code which tracks the mouse movements on a control and if the mouse hovers it will beep. I want it to draw specific images on Hover and when it leaves, draw a different image. How can I accomplish this? I subclassed the buttons to figure out … | |
I have a button created as follows: ~~~ HWND License; HBITMAP MainButtons; Case WM_CREATE: License = CreateWindowEx(WS_EX_TRANSPARENT, L"Button", L"License", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_BITMAP, 26, 77, 75, 23, hwnd, (HMENU)ID_LICENSE, hInst, 0); MainButtons = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAINBUTTONS), IMAGE_BITMAP, 0, 0, LR_SHARED); SendMessage(License, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)MainButtons); break; ~~~ … | |
Hey all, I've been searching Rohitab, CodeProject and various other sites to figure out how to write OPCodes to a file and cannot figure it out. I thought I'd ask here because it's the only site I have an account on and I usually get my answers here or hints. … | |
Does C++ Console apps have a TryParse equivalent.. I mean .Net has it for both C# and C++ but why does C++ Consoles NOT have this! Or am I just wrong and cannot find it? I was thinking of writing my own with templates that can be use for ANY … | |
How can I have my program modify itself? Example: Size = 1mb ..Run program once.. size = ++1mb On Second Run, check if itself is 1mb Or something of the sort :S. I need to be able to check if my program has ever been ran before.. So.. Is there … | |
Hey all, Back with another Win32 question. When I paint to my window (create a background image), what happens is that everything is fine until I draw the window off the screen causing it to invalidate everything.. When dragged back onscreen, my background is redrawn but my controls are all … | |
case WM_MOUSEMOVE: if (wParam & MK_LBUTTON) { RECT WindowRect; POINT CursorPos; GetWindowRect(hwnd, &WindowRect); GetCursorPos(&CursorPos); SetWindowPos(hwnd, 0, WindowRect.left - CursorPos.x, WindowRect.top - CursorPos.y, 291, 157, 0); } break; Hey Guys The above code isn't working for me. I'm trying to have the user Drag my borderless window but the thing just … | |
Is there anyway I can specialize JUST the Contains function of the class below? I tried for hours and cannot figure it out as I'm not too good at specialization but I learned templates recently. I want to do something like: [CODE] bool Contains(string ToFind) { //If typeof(T) == typeof(string) … | |
It reads in the whole file.. thing is, it crashes right after it hits the last line in the file.. the file is 115 lines long.. it prints all 115 lines but for some odd reason, it crashes right after :S If I remove the blank line at the end … | |
I'm trying to help someone with homework.. So you do not have to give me direct answers if you don't want to.. it is not my homework. [CODE] class Types { //No default constructor.. Types(int Param1, int Param2); }; class Objects { public: Types* Original; Objects(); ~Objects(); }; //The problem … | |
I need help changing my return type from int to vector<string>.. I don't want to have to pass the vector as a pointer to the function but rather I just want to return the vector itself as I no longer need to check the return type. If it fails, it'd … | |
K so atm, I'm having problems understanding ENDIF and IFDEF preprocessor stuff.. I want to Use a specific method if a file is included.. If not, use a different method.. Since toupper is defined in CCType I tried to check if that file was included.. if it was, use toupper … | |
Hey guys I'm having an extremely hard time splitting or combining values into binary.. [CODE] #define Chr(n) ((char)(n)) #define Ord(c) ((int)(unsigned char)(c)) int DecToBin(int Num) { int Bin = 0, Pos = 1; while (Num > 0) { Bin += (Num % 2) * Pos; Num /= 2; Pos *= … | |
I'm trying to convert this (Pascal) to C++.. My attempt is below this.. [CODE] function CompressString(const Str: string): string; var Destlen:longword; begin result := ''; Destlen :=BufferLen; if length(str) < 1 then exit; if compress(BufferString,destlen,PChar(Str),length(str)) = Z_OK then begin setlength(result,Destlen + SizeOf(Integer)); PInteger(@result[1])^ := Length(str); Move(bufferstring[0],result[5],Destlen); end; end; [/CODE] [CODE] … | |
My code is: [CODE] #include <windows.h> #include <iostream> using namespace std; struct ReplacementFlags { public: bool rfReplaceAll, rfIgnoreCase; ReplacementFlags(bool ReplaceAll = false, bool IgnoreCase = false) : rfReplaceAll(ReplaceAll), rfIgnoreCase(IgnoreCase) {} ~ReplacementFlags() {} ReplacementFlags& operator ()(bool ReplaceAll = false, bool IgnoreCase = false) { if((rfReplaceAll != ReplaceAll) && (rfIgnoreCase != IgnoreCase)) … | |
When do I really need to use Delete in Destructors? if I do Point P = new Point(); I've been told every time I use new, it stays in memory even when out of scope and that I should use delete to remove it.. so do i need to do … | |
I did not know WHERE to ask this as there is no "General" section on the site this site that I know of. Lets say I found code online but it's under the GPL 3 License.. I read it but it doesn't say that I cannot translate it from Pascal … | |
Am I wrong that the answer is 2?? Teacher refuses and says that it's 3 because the compiler spits out 3 for ans.. but if I do it manually with pen an paper or with the cout<<v2%v1++, it spits out 2 which is what I get on paper.. [CODE] #include … | |
How can I check if a template's parameter is empty? Or of a "certain type"? I'd prefer to check if it's empty or not rather than the type because if the wrong type is entered, it'd throw an error anyway.. But I definitely need to know if the parameter passed … | |
I'll get straight to the point as it's very difficult to do since I haven't found the answer on google or anywhere else. [CODE] Class ArrayOfTypes { vector<MyType> P; &MyType operator [](int I) = (MyType& PT) { if (P[I] != PT) { P[I] = PT; } return P[I]; } } … | |
Is it Dangerous to Derive from STD? Specifically std::string. Why I'm asking? I want to write a class that extends the functionality of std::string and a couple other std structs/classes.. So that when I do something like: String M = ""; M.Explode(........) it'll do the functionality in my class below. … | |
How can I get a variable amount of arguments in a function without providing how many arguments will be passed? For example, when you use a VA List, the first parameter must be the amount of arguments passed.. I don't want that. I want to just start passing any amount … | |
How can I do the following? I read up on Variable Arguments last time I asked this question (Mike pointed me in the right direction).. but it still does not let me define any number of them.. I Do not want to specify the first parameter and if I do, … |
The End.