c++

error: conversion from long int to non-scalar type, comparing an iterator to null

Hello I hope someone can explain this problem. This is the code: class Memory{ public: PacketPtr pkt; MemoryPort* port; MemCtrlQueueEntry(){}; }; And after I do: std::list<Memory*>::iterator lastIter = NULL; And I get the following error: error: conversion from long int to non-scalar type std::_List_iterator<DRAMMemor...

Importing png Files in Visual studio C++ Resource Editor

Hello, I would like to be able to import png file inside of Visual Studio Resource Editor so as to be able to use the embedded resource in different other projects . Is there a solution for that? I know that it works for bitmaps but i am interested in the pngs because of the "transparency" that is availble even on lower format [16x16] o...

Guaranteed file deletion upon program termination (C/C++)

Win32's CreateFile has FILE_FLAG_DELETE_ON_CLOSE, but I'm on Linux. I want to open a temporary file which will always be deleted upon program termination. I could understand that in the case of a program crash it may not be practical to guarantee this, but in any other case I'd like it to work. I know about RAII. I know about signals...

In which scenario do I use a particular STL Container?

Greetings :) I've been reading up on STL containers in my book on C++, specifically the section on the STL and it's containers. Now I do understand each and every one of them have their own specific properties, and I'm close to memorizing all of them... But what I do not yet grasp is in which scenario each of them is used. Could a kind...

shared_ptr in std::tr1

I am working on a platform with a gcc compiler however boost cannot compile on it. I am wondering what is the proper way to include the shared_ptr in std:tr1 on gcc? the file i looked in said not to include it directly, from what i can tell no other file includes it either :| ...

How can I transition my career away from Microsoft/c# oriented?

I'm mostly happy working in my c# job, but when I browse job listings (particularly startups), it seems that the positions I personally find to be most interesting require lots of experience with a linux stack, c++, and python. I coded in c++ for a few years (it was my first programming language), but that was nearly a decade ago. The jo...

Overloads of inherited member functions

Can a class overload methods that also exist in the publicly inherited interface? It seems like this is unambiguous and useful, but compilers (VC, Intel, GCC) all complain, at least by my construction. Below is a toy example. The inherited rebound() function has two clear overloads, yet this will not compile. If you rename the rebound()...

new on stack instead of heap (like alloca vs malloc)

Is there a way to use the new keyword to allocate on the stack (ala alloca) instead of heap (malloc) ? I know I could hack up my own but I'd rather not ...

Parse the Contents of String Array C++

Hi, I've read a file, and stored its contents into a string array. I need to change some numerical values, interpreted as characters by the compiler. The file is of the format: ABCDE,EFGHIJ KLMNOPQRS,45.58867,122.59750 I've searched and studied but haven't got onto anything too comprehensive. If someone can please tell me how to do ...

How can I synchronize two processes accessing a file on a NAS?

Here's the thing: I have two applications, written in C++ and running on two machines with different OS (one Linux and one Windows). One of this process is in charge of updating an XML file on a NAS (Network Attached Storage) while the other one reads this file. Is it possible to synchronize these two processes in order to avoid readin...

Cache, loops and performance

Some time ago I wrote a little piece of code to ask about on interviews and see how people understand concepts of cache and memory: #include "stdafx.h" #include <stdlib.h> #include <windows.h> #include <iostream> #define TOTAL 0x20000000 using namespace std; __int64 count(int INNER, int OUTER) { int a = 0; int* arr = (int*) H...

How to pass an array size as a template with template type?

My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows: #include <algorithm> #include <iostream> #include <iterator> template <typename TSize, TSize N> void f(TSize (& array)[N]) { std::copy(array, array + N, std::ostream_iterator<TSize>(std::cout, " ")); std::cout << s...

Use of GetGuiResources

Hello, Is it a good idea to use GetGuiResources(GetCurrentProcess(),GR_GDIOBJECTS) at the start of winmain, and before the last return to detect GDI leaks or more specifically objects I forgot to release ?Also I'm currently wondering why the first call in my progam returns 4 when there's no window yet. ...

Lambda expressions support in VS2008 SP1

Is there support for lambda expressions from C++ 0x in Visual Studio 2008 SP1? Example below throws me syntax errors. Is there any '-Cpp0x' flag for compiler or something? #include <algorithm> #include <iostream> #include <ostream> #include <vector> using namespace std; int main() { vector<int> v; for (int i = 0; i < 10; ++i) ...

How to create a filled arrow CustomLineCap?

The MSDN documentation has several open arrow examples but no examples for filled arrows. I just want to create a bigger arrow than the default LineCapArrowAnchor. I tried several things and can't get it to work. It should be simple, right? ...

Have you ever obtained a significant speedup by using boost::pool ?

I've played with boost::pool a few times in places where it seemed to me I was seriously hammering the heap with a lot of object "churn". Generally I've used boost::object_pool, or boost::pool_alloc as an STL template parameter. However the result is invariably that performance is virtually unchanged, or significantly worsened. I'm cu...

Check for value definedness in C++

Hello, I'm working in C++ and I need to know if a scalar value (for instance a double) is "defined" or not. I also need to be able to "undef" it if needed: class Foo { public: double get_bar(); private: double bar; void calculate_bar() { bar = something(); } }; double Foo::get_bar() { if ( undefined(bar) ) ...

State Diagram Generator

Is there a tool which generates the state space by seeing the code. i.e., if I give a class definition, it should generate the state machine. EDIT: State machine I mean is just the graphical representation of the classes and state changes. ...

Sphere World Implementation C++

What would be the best way to implement, store, and render spherical worlds, such as the ones in spore or infinity but without the in-between stages of spore, and multiple worlds ala infinity universe. Make no assumptions on how the planet itself is generated or its size/scale. ...

I see many examples of C++ with the use of "Foo ^ bar" - what is "^"?

Is that .NET related? It appears to be a pointer of some sort, what is the difference? Edit: I actually know it is the XOR operator, but look at this example from this page. void objectCollection() { using namespace System::Collections; **ArrayList ^as = gcnew ArrayList;** //... } What is this? Thanks. ...