c++

How to cast from bool to void*?

I'm trying to build cairomm for gtkmm on windows using mingw. Compilation breaks at a function call which has a parameter which does a reinterpret_cast of a bool to a void*. cairo_font_face_set_user_data(cobj(), &USER_DATA_KEY_DEFAULT_TEXT_TO_GLYPHS, reinterpret_cast<void*>(true), NULL); This is where the code breaks, and reason is "i...

I'm looking for syslog client source code

Does anyone have c++ source code to show how to send message to Syslog using winsock api. ...

How do I correct the error for this program to execute?

I have tried everything, this is my first C++ program and it not coming out right. I am receiving two error message. error7:1 warning: character constan too long for its type. and 7:error: expe //My first C++ program #include <iostream> int main(): { "-std::cout << "I will get it" << -std::cout::end1"; "-std::cout << "I hope so"...

Using static variable along with templates

I have a template class defined in a header file like this. Here I have defined a static variable as well: #ifndef TEST1_H_ #define TEST1_H_ void f1(); static int count; template <class T> class MyClass { public: void f() { ++count; } }; #endif And I have defined main() function in a different cpp file like thi...

C++ Assertions that Can Display a Custom String with Boost or STL?

Hi, I really want to be able to go: (in C++) assert( num > 0, "The number must be greater than zero!"); In C# XNA, they have a method that does exactly this: Debug.Assert( num > 0, "The number must be greater than zero!"); Is there some way to do this so that the runtime gives me a meaning full error not just "an assertion failed" ...

How to learn C++ as a C# programmer?

I've spent the past several years coding in .NET (C# mostly and some VB.NET) in a enterprise consulting environment. there are a lot of job opportunities with such a skill set, especially in the corporate environment. However, these roles are typically not very technical. Put it another way, these roles are unlikely to be from product co...

Storing a list of arbitrary objects in C++

In Java, you can have a List of Objects. You can add objects of multiple types, then retrieve them, check their type, and perform the appropriate action for that type. For example: (apologies if the code isn't exactly correct, I'm going from memory) List<Object> list = new LinkedList<Object>(); list.add("Hello World!"); list.add(7); li...

Returning the addresses of objects created outside the main() function.

I am trying to create a link list, but I am having trouble creating objects inside a function and assigning pointers to their addresses, since I believe they go out of scope when the function exits. Is this true? And, if so, how can I create an object outside the main and still use it? ...

How do I debug while running my program in Valgrind?

I was finishing up a code mod and wanted to run my program through Valgrind to make sure I've got all memory accounted for, but my program failed an assertion that doesn't fail when running on its own. Is it possible to stop in the debugger while running from Valgrind? I'm currently wading through the manual, but figured I could get my...

Native C/C++ code on an Android platform

Hi, Does anybody know the answer to the following questions? Is it possible for device manufactures can develop native C++ applications on an Android platform? How can I develop my own native C++ application / library that has an upper layer Java front-end / API on an Android platform? Thanks, Munish ...

Nameless enums in templates

Hi, Alot templated code looks like this: template <typename T> class foo { enum { value = <some expr with T> }; }; An example can be seen here in the prime check program and I've seen it in a Factorial implementation once too. My question is why use a nameless enum? Is there a particular reason to this? A static const int could ...

How ubiquitous is hash_map?

The hash_map and hash_set headers aren't included in the C++ standard yet, but they're available as extensions with all the compilers I've used lately. I'm wondering how much I can rely on these in real code without sacrificing portability. I'm working on tools projects that need to run on a host of architectures and compilers, includi...

disable vector fill value on resize? c++

I'm in a situation where i must use a c style function that returns the len copied. I decided i should resize to max, then resize to the length returned http://stackoverflow.com/questions/605539/expand-size-of-vector-passed-as-memory I know resize sets the value to fillValue (always 0?). So theres going to be pointless initialization (h...

How can I output execution display to console in Eclipse for remote C++?

I'm using Eclipse 3.4.1 with Hp/UX plugin for remote debugging of C/C++. It works very fine, except for one issue: whenever I compile my projects, the output display is Eclipse's console view, but when I run or debug any projects, the output window is the old and not-so-good MS-DOS command window. I haven't find any way to change this be...

convert vector of strings/doubles to arrays

I am using matheval library. Its functions take c-style parameters, for example: #include<matheval.h> char * evaluator_evaluate(void * evaluator, int count, char **names, double *values); In my case, I want to convert std::vector of names and std::vector of values to char ** and double * Also, every name correspond to a uni...

C++ - Circular array with lower/upper bounds ?

I want to create something similar to a double linked list (but with arrays) that works with lower/upper bounds. A typical circular array would probably look like: next = (current + 1) % count; previous = (current - 1) % count; But what's the mathematical arithmetic to incorporate lower/upper bounds properly into this ? 0 (lower b...

What does this error mean: "error: expected specifier-qualifier-list before 'type_name'"?

I'm a bit new to working with c/c++, so sorry if this is a dumb question. I've been working on the Cell processor and I'm trying to create a struct that will hold an spe_context_ptr_t, which will be used within the thread to launch an spe context and will also hold a pointer to something else that will be passed to the spu context from w...

return underlying array from vector

Will the array be deallocated and if so, what is a workaround? double * GetArrayFromVector( std::map<std::string, double> m, char ** names, int count ) { if(!names) return 0; std::vector<double> vec(m.size()); for (int i=0; i<count; ++i) { if(!names[i]) return 0; std::map<std::string, double>::iterator i...

VC++ 6.0 vector access violation crash. Known bug?

I'm trying to use a std::vector<>::const_iterator and I get an 'access violation' crash. It looks like the std::vector code is crashing when it uses its own internal First_ and Last_ pointers. Presumably this is a known bug. I'm hoping someone can point me to the correct workaround. It's probably relevant that the crashing function i...

How to set text in Carbon textfield on OSX?

I'm trying to set the text of a textfield using the Carbon API like this: ControlID editId = {'EDIT', 3}; ControlRef ctrl; GetControlByID(GetWindowRef(), &editId, &ctrl); CFStringRef title = CFSTR("Test"); OSErr er = SetControlData(ctrl, kControlEntireControl, kControlEditTextTextTag, CFStringGetLength(title), title); CFRelease(title...