c++

In C++, when can two variables of the same name be visible in the same scope?

This code illustrates something that I think should be treated as bad practice, and elicit warnings from a compiler about redefining or masking a variable: #include <iostream> int *a; int* f() { int *a = new int; return a; } int main() { std::cout << a << std::endl << f() << std::endl; return 0; } Its output (compiled with ...

C++ Compiler for Windows without IDE?

I'm looking for just a compiler for C++ (such as g++) for Windows, that I could run in my cmd. I'm using notepad++ as my text editor and I want to set up a macro in there that can compile my programs for me. I do not wish to install Cygwin though. Any suggestions? Thanks in advance :) ...

Simple Question: Passing object with state, C++

I'm not an C++ expert and still do not have a great intuitive grasp of how things works. I think this is a simple question. I am having trouble passing objects with state to other objects. I'd prefer to avoid passing pointers or references, since once the initialized objects are setup, I call them millions of times in a tight loop. I ...

trapping http/https requests in windows

Is it possible to trap http/https requests for filtering in windows? ...

Appending ints to char* and then clearing

I'm working on a project using an Arduino and as such, I'm reading from a serial port (which sends ints). I need to then write this serial communication to an LCD, which takes a char*. I need to read several characters from the serial port (2 integers) into a string. After both have been received, I then need to clear the string to prep...

How to declare factory-like method in base class?

I'm looking for solution of C++ class design problem. What I'm trying to achieve is having static method method in base class, which would return instances of objects of descendant types. The point is, some of them should be singletons. I'm writing it in VCL so there is possibility of using __properties, but I'd prefer pure C++ solutions...

My C Program provides a callback function for a hook. How can I keep it alive, un-kludgily?

Currently, I'm spawning a message box with a OS-library function (Windows.h), which magically keeps my program alive and responding to calls to the callback function. What alternative approach could be used to silently let the program run forever? Trapping 'Ctrl-c' or SIGINT and subsequently calling RemoveHook() for a clean exit would ...

STDIN in Netbeans

Hi Does someone know.. how to read files to STDIN in Netbeans. I have a Problem my Program in Netbeans. The Program works like this : ./myprog < in.txt It's a C++ Project. Any Ideas ? Edit : I have Proglems with setting up netbeans . where can i say : READ/USE THIS FILE ? On the Console it just works fine ! ...

Is there any Win32 API to trigger the hibernate or suspend mode in windows?

Is there any Win32 API to put the machine into hibernate or suspend mode? I read MSDN and found that WM_POWERBROADCAST message gets broadcasted when power-management events occur. I thought of simulating the same with PostMessage(WM_POWERBROADCAST). Is this the correct way of doing or any Win32 API exists to achieve this? ...

C++ idiom to avoid memory leaks?

In the following code, there is a memory leak if Info::addPart1() is called multiple times by accident: typedef struct { }part1; typedef struct { }part2; class Info { private: part1* _ptr1; part2* _ptr2; public: Info() { _ptr1 = _ptr2 = NULL; } ~Info() { delete _ptr1; delete...

How to read a .pdf file programmatically and convert it into audio (.mp3 format)?

I want to parse a PDF file from my C# app and create an audio file off it. How would I do that ? I'm particularly looking for a good pdf to text library or a way to strip a pdf file off its text. ...

How can I know the type of a file using Boost.Filesystem?

I'm using Boost but I cannot find complete (or good) documentation about the filesystem library in the installation directory nor the web. The "-ls" example I found has been quite a helper but it's not enough. Thanks in advance :) ...

Asynchronous Windows Console input whilst outputting

Hey all, Long time reader, first time poster :D I'm having issues trying to read input whilst outputting at the same time. I need a server console for my game which can receive input whilst outputting and not mess up the buffer. For example, I'm typing "Hello world" and in the process, player deaths, kills, etc. are being outputted in...

Returning reference to static local variable in C++

This question is just for my better understanding of static variables in C++. I thought I could return a reference to a local variable in C++ if it was declared static since the variable should live-on after the function returns. Why doesn't this work? #include <stdio.h> char* illegal() { char * word = "hello" ; return word ; } c...

How to change a value in memory space of another process

Hi all, If you could help me with this dilemma I have. Now, I know C \ C++, I know asm, I know about dll injection, I know about virtual memory addressing, but I just can't figure out how software like CheatEngine, and others, manage to change a variable's value in another process. For those who don't know, 3rd party cheat engine tools ...

Html renderer with limited resources (good memory management)

I'm creating a linux program in C++ for a portable device in order to render html files. The problem is that the device is limited in RAM, thus making it impossible to open big files (with actual software). One solution is to dynamically load/unload parts of the file, but I'm not sure how to implement that. The ability of scrolling is...

Is this valid C++ code?

Hi, I just wanted to know whether is this following block of code fully valid in C++: class A { public: virtual bool b() = 0; }; class B { public: virtual bool b() = 0; }; class C: public A, public B { public: virtual bool A::b() { return true; } virtual bool B::b() { return false; } }; Using VS2008 it compi...

Xerces-C problems; segfault on call to object destructor

I've been playing around with the Xerces-C XML library. I have this simple example I'm playing with. I can't seem to get it to run without leaking memory and without segfaulting. It's one or the other. The segfault always occurs when I delete the parser object under "Clean up". I've tried using both the 2.8 & 2.7 versions of the l...

Photoshop's "Screen" mode in DirectX

Edit: Problem solved! See end of post. How to implement "Screen" blending mode from Photoshop in DirectX 8? Info, i've found on this topic (http://www.ziggyware.com/readarticle.php?article_id=228): Result = 1 – (1 – destination) * (1 – source) Result = 1 – (1 – source – destination + destination * source) Result = 1 – 1 + source + de...

i need a good website to learn c++

i want to learn C++; and i already have a compiler. i already know a few programming languages including: BASIC (yes, the dos version) visualBasic (using VisualBasic Express 2006 or 8 i'm not quite sure) Java PHP HTML (if we count that) so it doesn't need to be for absolute beginners; although if you find one post it too. ...