c++

How to create gradient mesh in code (C++)?

So How to create gradient mesh in code (C++)? I need some Open Source Lib... and tuts on how to use it... ...

How could I refactor this code with performance in mind?

I have a method where performance is really important (I know premature optimization is the root of all evil. I know I should and I did profile my code. In this application every tenth of a second I save is a big win.) This method uses different heuristics to generate and return elements. The heuristics are used sequentially: the first h...

Static template field of template class?

Hello! I've got this code to port from windows to linux. template<class T, int Size> class CVector { /* ... */ }; template<int n, int m> class CTestClass { public: enum { Size = 1 << n }; private: static CVector<int, Size> a; // main.cpp:19 }; template<int n, int m> CVector<int, CTestClass<n, m>::Size> CTestClass<n, m>::a; // mai...

Why is this error: reference to ‘statusBar’ is ambiguous.. coming? Is this a bug?

I created a QMainWindow using QT Designer. As we know, it has statusBar by default. By default, QT Designer gave its objectname as "statusBar". Now, when I tried to call like:- statusBar()->showMessage(tr("File successfully loaded."), 3000); as we have a function with prototype: QStatusBar * QMainWindow::statusBar () const The Comp...

How to check if file is/isn't an image without loading full file? Is there an image header-reading library?

edit: Sorry, I guess my question was vague. I'd like to have a way to check if a file is not an image without wasting time loading the whole image, because then I can do the rest of the loading later. I don't want to just check the file extension. The application just views the images. By 'checking the validity', I meant 'detecting and...

Functional Programming in C++

Can someone guide me how do functional programming in C++? Is there some good online material that I can refer? Please note that I know about the library FC++. I want to know how to do that with C++ standard library alone. Thanks. ...

Why is typeid not constant like sizeof

Why is typeid(someType) not constant like sizeof(someType) ? This question came up because recently i tried something like: template <class T> class Foo { BOOST_STATIC_ASSERT(typeid(T)==typeid(Bar) || typeid(T)==typeid(FooBar)); }; And i am curious why the compiler knows the size of types (sizeof) at compile time, but not the typ...

memset, memcpy with new operator

Can I reliably use memset and memcpy operators in C++ with memory been allocated with new? Edited: Yes, to allocate native data type Example BYTE *buffer = 0; DWORD bufferSize = _fat.GetSectorSize(); buffer = new BYTE[bufferSize]; _fat.ReadSector(streamChain[0], buffer, bufferSize); ULONG header = 0; memcpy(&header, buffer, sizeof(...

Convert Hex Char To Int - Is there a better way?

I have written a function to take in the data from a Sirit IDentity MaX AVI reader and parse out the facility code and keycard number. How I am currently doing it works, but is there a better way? Seems little hackish... buff & buf are size 264 buf and buff are char Data received from reader: 2009/12/30 14:56:18 epc0 LN:001 C8...

Check if a binary number has a '0' or a '1' at a specific position

Hi I'd like to check if a binary number has a '0' or a '1' at a specific position. example: if the binary number is: 101000100 checking at position zero (that is at the rightmost '0') should result in '0'. checking at position 2 should result in '1'. checking at position 3 should result in '0'. checking at position 6 should result i...

Unix socket: hostent makes memory leaks

Hello, I am writing client for TCP connection and conversion from IP to socket_addr makes memory leaks. There is following process: #include <netdb.h> #include <sys/socket.h> #include <sys/types.h> /** there is some code like method header etc. */ hostent * host = gethostbyaddr( ip, 4, AF_INET ); // ip is char[4], I use IPv4 if ( ...

Can getline() be used to get a char array from a fstream

Hi, I want to add a new (fstream) function in a program that already uses char arrays to process strings. The problem is that the below code yields strings, and the only way i can think of getting this to work would be to have an intermediary function that would copy the strings, char by char, into a new char array, pass these on to the...

Is Loop Hoisting still a valid manual optimization for C code?

Using the latest gcc compiler, do I still have to think about these types of manual loop optimizations, or will the compiler take care of them for me well enough? ...

Intel C++ compiler as an alternative to Microsoft's?

Is anyone here using the Intel C++ compiler instead of Microsoft's Visual c++ compiler? I would be very interested to hear your experience about integration, performance and build times. ...

CMFCToolbar layout not restored properly between sessions

I'm having a problem with the CMFCToolbar class where the positions of the toolbars are not being restored properly between sessions. Here is a screen shot of how the toolbars are arranged before the app is closed: Here is a screen shot of how the toolbars are restored when the app is launched again: Notice the large gap that appe...

What would be a best way to notify an application (C++ or Java) when underlying DB changes?

I'm writing a C++ console application that needs to respond to a change in a specific field of a database table. Though I can keep sending a query to check the field periodically, I'd like to avoid this because multiple instances of this application might be running. I have heard of the Query Notification feature of SQL Server 2005 but i...

C# and C++ in relation to C

I've never programmed using C or whatever but I use this site a lot so as you can imagine I run into them quite a lot. And due to the fact I don't really understand the languages this is a question Google can't really answer. So in simple terms what are the differences between each of these languages. I assume they are related. All I kn...

boost asio io_service.run() question

I was just going over the asio example here: http://www.boost.org/doc/libs/1%5F39%5F0/doc/html/boost%5Fasio/example/chat/chat%5Fserver.cpp My question is about their usage of the io_serice.run() function. The documentation for the io_service.run() function says: "The run() function blocks until all work has finished and there are no mo...

C++: Get data from MIDI message (DWORD)

Hello I've written a simple MIDI console application in C++. Here's the whole thing: #include <windows.h> #include <iostream> #include <math.h> using namespace std; void CALLBACK midiInputCallback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { switch (wMsg) { case MIM_MOREDATA: case MIM...

writing pexpect like program in c++ on Linux

Is there any way of writing pexpect like small program which can launch a process and pass the password to that process? I don't want to install and use pexpect python library but want to know the logic behind it so that using linux system apis I can build something similar. ...