c++

Has anyone an example for wrapping a function in C++?

I have searched online a lot but I couldn't find an example that works with g++, all examples work with gcc. The error I keep getting is wrap_malloc.o: In function `__wrap_malloc(unsigned int)': wrap_malloc.cc:(.text+0x20): undefined reference to `__real_malloc(unsigned int)' wrap_malloc.o: In function `main': wrap_malloc.cc:(.text+0x37...

implicit cast through contructor with multiple arguments

If I have these 2 constructors for MyClass: MyClass(int n1); MyClass(int n1, int n2); and an overloaded (non-member) operator+: MyClass operator+(MyClass m1, const MyClass& m2); This enables me to write code like this: MyClass m; 5 + m: which I guess uses implicit cast through the defined constructor, correct? Is there anyway t...

How do I leverage a control from a C++/CLI project for use in my WPF application?

First of all, my knowledge of C++ is effectively zero. I'm a .NET developer but even my interop experience is minimal. I have found an example of a control written in C++/CLI that grabs and displays a webcam feed using DirectShow. I'd like to take this example and utilize it from my WPF application. I've tried (and butchered) several d...

Another static initialization order problem in C++

This is another variation of an old theme: The initialization order of static objects in different translation units is not defined. Below is a stripped-down example of my particular szenario. The classes G and F are non-POD types. F depends on G is the sense that to construct an instance of F you need some number of instances of G. (Fo...

RTP Malformed Packet formed using CCRTP library. Not sure what is going wrong.

Trying to form RTP packets using CCRTP library. I use Wireshark to look at the packets, and see that the packets appear as MALFORMED RTP packet, and fragmented IP packets. Please help. I am not sure how to attach the error pcap file here. So I am specifying the error packets as .csv format right here. ---------------------------- ERR...

How do I make a C++ program that filter out non-integers?

Something like this cout << "Enter the number of columns: " ; cin >> input ; while( input != int ){ cout << endl <<"Column size must be an integer"<< endl << endl; cout << "Enter the number of columns: " ; cin >> input ; } ...

Accessing a Pointer to a pointer in C++

Hi I am using a 3rd party library in my iPhone application that uses C++ one of the methods i need to use returns a pointer to a pointer of a class. like follows. DLL classAttributes** getAttributes(); I can successfully call the method and return the value into a pointer to a pointer like so; classAttributes **attributes = cPPClass-...

Using kbhit() to pause terminal output?

I took my first 'fundamentals of programming' lab session at uni today. One thing struck me as odd, though: the use of while(! _kbhit()) from conio.h (which I'm sure is a C unit?) to 'pause' the console output. Is this the best way to do this? What do I need to watch out for when using it? Is my tutor absolutely bonkers? I only ask beca...

exception handling

Hi guys, I get the following core dump msg: terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr Abort - core dumped I am reading a 14 digit hexadecimal number from a large file. periodically i notice that there are these blank lines (well i am not sure what it is. How do I handle this ex...

What is the normal convention for naming and using iterators in C++?

I feel like I'm unprofessional in the way I name and use iterators. What I mean by that is that I "feel" like I should be calling them something else, but I always name them based on the "it_" prefix, and after a while, in a long function, the names start to all look alike. Additionally, I always wonder if I'm doing things a "strange" w...

C++ metaprogramming question

Hello! I have the following problem: Suppose I have some basic counter class Counter. And suppose we also have some sets of classes, that can be counted. Let's name some of them class CountedA and class CountedB. Now, every class, which can be counted (such as CountedA and CountedB) has the following statically declared parts: one enu...

BITMAPINFOHEADER to BitmapSource

Hi, I have c# app, that has a callback method, and the only parameter this method has is an IntPtr that is a pointer to a BITMAPINFOHEADER Structure. I need to convert it to a BitmapSource object to use with WPF. Using Marshal.Read* I can know its width and height etc... but I don't know how to generate a BitmapSource... Anyone knows h...

What's an effective way to parse command line parameters in C++?

Is there a really effective way of dealing with command line parameters in C++? What I'm doing below feels completely amateurish, and I can't imagine this is how command line parameters are really handled (atoi, hard-coded argc checks) in professional software. // Command line usage: sum num1 num2 int main(int argc, char *argv[]) {  ...

C++ Declspec align

Hi am new to Visual C++, Could Someone please explain what ConfParams() declared in a structure does __declspec(align(BYTE)) struct ConfParams { BOOL m_timeout; DOUBLE m_caution; ConfParams(); } ...

Is it possible to read dos files in linux using an ifstream

When I use the std::ifstream to open a file that has been written in dos format, the ifstream does not seem to be able to open the file correctly since when I call good() on the stream afterwards it fails (returns false). I tried opening the file in binary mode as well as the default "in" mode and neither worked. If I convert the file ...

Conf file parser

I thought there was a boost library that allowed me to parse unix conf files? I believe it also had other features, i.e. it could parse windows ini files and I think XML based config files might have been done or was on the way too. Any idea what that's called? I'm looking through the program options library and it doesn't look like t...

Simple class concepts in C++ (cards in a deck)

Hey you guys were absolutely great with my last problem so hopefully you can help clarify something else to me. Classes confuse me! For this particular assignment, we are to do the classic 'Cards in a Deck' program. We are to make two classes, one called 'Card' and the other 'Deck'. Now I've gotten a large chunk of this done so far but...

Global variables in C++

I am working with some C++ code that has a timer and the timer runs this: char buf[1024]; ZeroMemory(&buf, sizeof(buf)); somefunction(buf); // this put stuff into buf otherfunction(buf); // this do stuff with buf somefunction() does a web request and InternetReadFile() puts the data in "buf" But I need to be able to read the previous...

C++ Virtual Const Function

Hello all, Given the following snippet, class Base { public: virtual void eval() const { cout<<"Base Const Eval\n"; } } class Derived:public Base { public: void eval() { cout<<"Derived Non-Const Eval\n"; } } int main() { Derived d; Base* pB=&d; pB->eval(); //This will call the Ba...

Having a constant to be used across entire application. Use #define or variable

Possible Duplicate: static const vs #define Hello all, in C++, to define a constant to be used across the entire application, what is your guys usual practice? #define WINDOWS_HEIGHT 1024 or const int WINDOWS_HEIGHT = 1024; Thanks. ...