c++

Why have QString in struct sometimes a bad-ptr?

Hi there! I've got an complicated error. The software send PrintParamters to a Printer a couple of times. At a certain moment all QStrings of the Parameter Struct are broken (bad ptr) Is there an general issue with QStrings in Structs? here is the struct I'm using: typedef struct RecorderPrintParam { ES_DataType xxxxxxxxxx; bool ...

Default parameters of struct templates

I have a template struct tree_parse_info declared as follows: template < typename IteratorT, typename NodeFactoryT, typename T > struct tree_parse_info { // ... }; The compiler allows the follows code: tree_parse_info<> m_info; Why does this code compile even though we do not have default template parameters for the ...

How to implement an associative array/map/hash table data structure (in general and in C++)

Well I'm making a small phone book application and I've decided that using maps would be the best data structure to use but I don't know where to start. (Gotta implement the data structure from scratch - school work) ...

Debugging asserts in Qt Creator

When I hit a normal assert statement while debugging with Visual Studio I get the option to break into the debugger so I can see the entire stack trace and the local variables, not just the assert message. Is it possible to do this with Qt Creator+mingw32 and Q_ASSERT/Q_ASSERT_X? ...

Pass by reference more expensive than pass by value

Hello everyone, this question has been bugging me for a while, so i thought i'd ask. Is there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be? Thanks. ...

std::map problem on gcc 3.4, crashes in std::less<unsigned> when using find

Definition: std::map<unsigned, CItem*> m_map; void RegisterEvent(unsigned eventID) { std::map<unsigned, CItem*>::iterator it = m_map.find(eventID); <<< crashes if (it == m_map.end()) { m_map[eventID] = new CItem(); } else { ... } } The marked row crashes in std::less on second call, the first call works. When watchi...

Modifying old Windows program for Mac OS X

This application was written for windows back in 1998, I loved using this program, Now I want to learn how to make it work on Mac, And maybe changing and adding functionality, The problem is I don't know where to start, I Have studied C++ php, javascript, But don't really know how to read this code. or where to start. Thanks for t...

C++ Namespaces, comparison to Java packages

I've done a bunch of Java coding recently and have got used to very specific package naming systems, with deep nesting e.g. com.company.project.db. This works fine in Java, AS3/Flex and C#. I've seen the same paradigm applied in C++ too, but I've also heard that it's bad to view C++ namespaces as direct counterparts to Java packages. Is...

Difficult concurrent design

I have a class called Root which serves as some kind of phonebook for dynamic method calls: it holds a dictionary of url keys pointing to objects. When a command wants to execute a given method it calls a Root instance with an url and some parameter: root_->call("/some/url", ...); Actually, the call method in Root looks close to this:...

C++ classes , Object oriented programming

I have a very simple class named person which is given below , I have a problem with only two functions , i.e setstring () function and setname() function , I am calling setstring() function from the setname function. The only problem is when in the main function I write Object.setname(“Zia”); The result is ok as shown in the output s...

Possible to embed a C++ dx renderer in a C# app without using managed c++?

I have a renderer written in C++ and directX. I now want to write a (level / scene / UI) editor and if possible / realistic I would prefer to write the interface to my editor in C#/.net Is this at all feasible, without going down a route of managed c++? Can I expose the necessary interface from my renderer to a C# app, without managed...

Is Short Circuit Evaluation guaranteed In C++ as it is in Java?

In Java, I use if (a != null && a.fun()); by taking full advantage of short-circuit evaluation and expression are evaluated from left to right? In C++, can I do the same? Are they guarantee to portable across different platform and compiler? if (a != 0 && a->fun()); ...

how to use my_alloc for _all_ new calls in C++?

Imagine I'm in C-land, and I have void* my_alloc(size_t size); void* my_free(void*); then I can go through my code and replace all calls to malloc/free with my_alloc/my_free. How, I know that given a class Foo, I can do placement new; I can also overload the new operator. However, is there a way to do this for all my C++ classes? (...

basic question c++, dynamic memory allocation

Suppose I have a class class person { char* name; public: void setname(const char*); }; void person::setname(const char* p) { name=new char[strlen(p)]; strcpy(name,p); name[strlen(p)]='\0'; } My question is about the line name=new char[strlen(p)]; suppose the p pointer is pointing to string i.e “zia” , now strlen(p) will return 3 it...

Strange performance behaviour for 64 bit modulo operation

The last three of these method calls take approx. double the time than the first four. The only difference is that their arguments doesn't fit in integer anymore. But should this matter? The parameter is declared to be long, so it should use long for calculation anyway. Does the modulo operation use another algorithm for numbers>maxint...

Looking for a library for simple protocol implementation

Hello, I need to implement a simple over-the-network interaction in C++ and I've been wondering whether there are libraries that do that already. My protocol basically sends messages and receives responses. Each message is just a set of 3-4 values of basic data types. I would like to find a library (or libraries) that can do one or more...

Xcode cannot find #Include<> header

I'm trying to get Xcode to import the header file for Irrlicht. #include <irrlicht.h> It says "Irrlicht.h. No such file or directory". Yes Irrlicht.h with a capital I, even though the #include is lowercase. Anyway I added "/lib/irrlicht-1.6/include" in the header search paths for the Xcode project, yet it still doesn't find it. The ...

Ambiguous overload accessing argument-less template functions with variadic parameters

Yeah, the title can scare babies, but it's actually quite straightforward. I am trying to store a function pointer to a specialized template function, namely boost::make_shared (boost 1.41), as illustrated: boost::shared_ptr<int> (*pt2Function)() = boost::make_shared<int>; However, it won't compile (GCC 4.4.1) due to the fact that bo...

How to detect if an application is running under KVM?

I already know how to detect VMWare and VirtualPC, but I want to know how to do this in Kernel Virtual Machine. I would like the code to be in C or C++. ...

C++ linking error LNK2019

Can anybody please help me to configure Visual Studio 2005 (if that's the solution to the problem). I'm using some external libs and I'm getting this error: 1>Compiling... 1>main.cpp 1>c:\documents and settings\mz07\desktop\project\vs8test1\vs8test1\main.cpp(99) : warning C4996: 'getch' was declared deprecated 1> c:\program files...