462 Posted Topics
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); … | |
Re: You haven't provided enough for me to guess what your trying to do.. You also cannot just implicitly convert a HWND to an HDC. It doesn't work like that. Putting the code in order, you can see that you had some HWND's being used as if it was a DC. … | |
Re: People class doesn't have a declaration for the default constructor, String needs to be defined through its namespace. std::string X. And std::name because you do not have "using namespace std;" In the people class under the public inheritance, add: People(); And finally, PrintInfo has no definition. | |
Re: Never tested this but the formula seems correct :S RGB to CMY: http://www.easyrgb.com/index.php?X=MATH&H=11#text11 CMY to CMYK: http://www.easyrgb.com/index.php?X=MATH&H=13#text13 EDIT: Oh wow.. didn't realize this was a grave dig -_- void RGBToCMYK(int R, int G, int B, int &C, int &M, int &Y, int &K) { C = 1 - (R / … | |
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& … | |
Re: You need to link the correct .lib/.dll/.a/.o files to your program. `#pragma comment('lib', "user32.dll"); ` Would be an example of doing so in Vs2010. I may have made a mistake doing the code above since I don't have access to a compiler to test atm, but it's something like that. … | |
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>& … | |
Re: You did not escape the back-slash character. All strings/literals will have this behaviour as the first back-slash will escape the following character so inorder to have a back-slash, you must escape it with another. You either need to do: `C:\\Directory1\\Directory2\\Music.mp3` OR: `C:/Directory1/Directory2/Music.mp3` Command prompt will complain about the same thing … | |
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 … | |
Re: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12 That's what I read to learn template compilation. It says that putting everything in the header can bloat your executable though. | |
Re: I don't know if you mean reading the file's name? OR whether you mean reading data from the file and outputting a list of names from the data. //Read a file's contents and output it to a string. For your purpose, you can even use GetLine which I have not … | |
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 … | |
Re: What you did is already correct.. the reserve allowed it to survive the clear.. Your vector will have a size of 0 but a capacity of 10000. All information in the vector is lost and cannot be accessed. If an access is attempted, it will assert out of range. Basically … | |
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) : … | |
I'm trying to figure out why I should convert all my unsigned ints/shorts to size_t. I'm doing the things below but I'm not sure which one to use and which type to iterator my for-loop with: unsigned short Size() { return vector.size(); } int Size() { return vector.size(); } unsigned … | |
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) << … | |
Re: This may or may not be what you are trying to accomplish: #include "stdafx.h" using namespace System; array<Byte^>^ StringToByteArray(String^ Str) { array<Byte^>^ bytes = gcnew array<Byte^>(Str->Length); for(int I = 0; I < Str->Length; I++) { bytes[I] = Byte(Convert::ToByte(Str[I])); } return bytes; } int main(array<System::String ^> ^args) { array<Byte^>^ bytes = … | |
Re: In your assignment operator, you should be checking for self assignment. In your addition/subtraction operators, I'm not sure that you need that temp there. Your ostream works right out of the box. The reason you're getting these errors is because the files aren't added to your debug and release upon … | |
Re: Switch to Codeblocks even though I love the Dev-C++ interface, the Mingw for it is far outdated. Also you need to post more detail and probably the function because we cannot guess what you need help with/what the problem may be. | |
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, … | |
Re: From a class I wrote a while back.. I used: <td(.*?)</td> which is a non greedy regex so it will return all matches. Anyway this is the stuff I was speaking of. I used it to create a stock ticker that grabbed Stocks from a website and display their values, … | |
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 … | |
Re: Allman style.. the others are so difficult to track which braces match which.. well for me at least. | |
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 … | |
![]() | Re: Line 53 as well.. `ostream &Circle::operator << (ostream &mystream,Circle &c)` |
Re: Double Buffer the form.. Click it and set the buffering property to double. | |
Re: For how it could be done see: class Members { private: vector<int> Data; public: Members(){} Members(int I); ~Members(){} int size(); Members& operator [](int I); operator const vector<int>& () const; Members& operator ()(int I); Members& operator << (const int& t); Members& Insert(int Index, int ValueToInsert); Members& Remove(int Index); }; int Members::size(){return … | |
What should I be using? Should I be using _T? or L? Or Neither? I know some functions end with the A for Ansi and some end in W for the Unicode version but I have no clue what I want to use. if I use _T would I have … | |
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 … | |
Re: //For .Net: enum {F9_KEYID = 1, F10_KEYID = 2} ; RegisterHotKey(0, F9_KEYID, MOD_NOREPEAT, VK_F9); RegisterHotKey(0, F10_KEYID, MOD_NOREPEAT, VK_F10); MSG msg = {0}; PeekMessage(&msg, 0, 0, 0, 0x0001); //0x0001 means No Repeat.. TranslateMessage(&msg); switch(msg.message) { case WM_HOTKEY: if(msg.wParam == F9_KEYID) { MessageBox::Show("F9 Pressed"); } else if(msg.wParam == F10_KEYID) { MessageBox::Show("F10 Pressed"); … | |
Re: Write the variable to a file everytime it changes, read it with your other program. | |
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 … | |
Re: I don't think you can redistribute their files but if your not using an installer, you could open the project menu -> Properties -> C/C++ -> Code Generation -> RunTime Library Set it to /MDd. Maybe this will work for the installer as well depending on how your making it. … | |
Re: You have to uninstall Mingw first.. and DevC++.. I'm on Windows 8 and it works VS2010 and codeblocks works fine.. Consumer Preview here. | |
Re: I know that the C-Style cast aka (Type)Variable is basically trial an error of all the casts put together. At least that's what I was taught. Example: (double) Variable would be equivalent to trying all of the following and whichever works first, that's used: const_cast<double> Variable reinterpret_cast<double> Variable static_cast<double> Variable. … | |
Re: Create a WINAPI/Win32 Application.. Remove all the callbacks and stuff.. Use WinMain instead and it will have no console. | |
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 … | |
typedef union { unsigned Color; struct { unsigned char B, G, R, A; }; } RGB, *PRGB; inline RGB Rgb(int R, int G, int B) {RGB Result = {((COLORREF)((BYTE)(R)|((BYTE)(G) << 8)|((BYTE)(B) << 16)))}; return Result;} inline RGB Rgb(COLORREF Color) {RGB Result = {Color}; return Result;} The above is my code … | |
Re: Deceptikon gave an amazing answer but I want to share what I figured out by accident yesterday. You can declare a function inside a function via a data structure: std::thread f() { typedef struct { void somefunction(){} } t; return t.somefunction(); } //OR std::thread f() { struct t { void … | |
I have the following: typedef union { unsigned Color; struct { unsigned char B, G, R, A; }; } RGB, *PRGB; Then I have: RGB Rgb(XYZ Xyz) { RGB Result; double X = Xyz.X / 100; double Y = Xyz.Y / 100; double Z = Xyz.Z / 100; double Red … |
The End.