c++

WMI query for Win32_BaseBoard returns no results

The following C++ code to retrieve the motherboard info via WMI works on most machines, except one: IEnumWbemClassObject* pEnumerator = NULL; hres = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("Select * from Win32_BaseBoard"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); if (FAILED(hres)) { // handl...

How to utilize sqlite for undo/redo features?

I'm writing a desktop application to do vector drawing in C++, and considering using sqlite to back my undo/redo feature. Has anybody used sqlite for undo/redo features? How does it work out for you? Clarification: I was aware of the stack approach, I have even implemented one application with that approach. The problem I encountered...

Is it OK to return a const reference to a private member?

I need to implement read-only access to a private member container. If I return a constant reference is it possible to const_cast it and obtain a full access to the member? What's the technique to be used? Thanks. ...

Is there an un-buffered I/O in Windows system?

I want to find low-level C/C++ APIs, equivalent with "write" in linux systems, that don't have a buffer. Is there one? The buffered I/O such as fread, fwrite are not what I wanted. ...

I am using a comet server and I want it to interact with C++

I am using persevere for an application I am writing that controls remote hardwere. Persevere is written in Java and doesn't supply an alternative API. I am using a web-based GUI as the control panel. So far, so good. I can get and set data using REST channels like dojo does but the problem is that I don't really know how to use REST c...

Is it safe to call temporary object's methods?

I have a function which shall return a char*. Since I have to concatenate some strings, I wrote the following line: std::string other_text; // ... return ("text" + other_text).c_str(); I know that I could avoid the question naming the string I want to return. I just want to take the chance to make a more general question: is it safe ...

Assertion in VS2008 but not in VS2005

Hello, After switching from VS2005 to VS2008 SP1, I found an issue that I can't explain. A program works fine under VS2005 in both release and debug mode. Under VS2008, when entering the debugger an assert is raised. If I let the program run (in debug or release mode), no assertion at all. I spent almost two days on this and I don't un...

What are potential dangers when using boost::shared_ptr?

What are some ways you can shoot yourself in the foot when using boost::shared_ptr? In other words, what pitfalls do I have to avoid when I use boost::shared_ptr? ...

create XML files from C++ program

I have this variable, a vector of double pointers like: vector<double*> myIntersections; which contains a vector whose elements are all a two dimensional vector of doubles. I want to create a XML file (called for example myfile.axl - with this specific extension) in which each row of the file is given by each element of the vector (so...

Assigning to temporary (like 5 = 10 but for user-defined types)

Hi, after doing some test-code for this link : http://stackoverflow.com/questions/701313/is-it-safe-to-call-temporary-objects-methods I found a rather strange feature of the c++ language, which I'm not sure how it works : struct Test{ int i; Test(int ii):i(ii){} Test& operator=(int ii){ i = ii; return *this; } ...

(*this)[i] ?

I overloaded the [] operator in my class. Is there a nicer way to call this function from within my class other than (*this)[i]? ...

Initializing in constructors, best practice?

I've been programming in C++ a while and I've used both methods: class Stuff { public: Stuff( int nr ) : n( nr ) { } private: int n; } Or class Stuff { public: Stuff( int nr ) { n = nr; } private: int n; } Note: This is not the same as this, similar but not the same. What is considered best pract...

How to call a method inde an Xlam from C++ Unmanaged XLL file

I have an Xlam addin with some methods, I'd like to call these methods from a C++ Unmanaged Xll file, is there a way to do this? ...

Rewriting C++ methods in C

How can I make equivalents to these methods in C? I read somewhere that they could be "replaced with functions that take a structure pointer as the first parameter," but I'm not sure how to do this, if that is the right thing to do. struct SCustomKeys { struct SCustomKey Save[10]; struct SCustomKey Load[10]; struct SCustomK...

How does a C++ developer shine in C# job applications

I have enjoyed a long career in C++ development, across several sectors and am now at a senior level. I am thinking of moving on from my current employer. However, the world seems to have moved on. Two years ago I saw a 50/50 split in C++ vs C# roles, today it's more like 20/80 in C#'s favour. Do any SOers have advice on how to m...

C++ Symmetric Binary Operators with Different Types

Hello, I am learning C++ and I was wondering if I could gain some insight into the preferred way of creating binary operators that work on instances of two different types. Here is an example that I've made to illustrate my concerns: class A; class B; class A { private: int x; public: A(int x); int getX() con...

Making a template parameter a friend?

Example: template<class T> class Base { public: Base(); friend class T; }; Now this doesn't work... Is there a way of doing this? I'm actually trying to make a general class sealer like this: class ClassSealer { private: friend class Sealed; ClassSealer() {} }; class Sealed : private virtual ClassSealer { // ... };...

C++ union array and vars?

There's no way to do something like this, in C++ is there? union { { Scalar x, y; } Scalar v[2]; }; Where x == v[0] and y == v[1]? ...

debug vs release build in Visual studio c++ 2008 win32 runtime issue

I have a simple udp listener written in c++ using win32 when I compile and run the program under debug mode it works perfectly, and I'm clearly able to see the information from the packets that I'm receiving. When I run this same code as a release build it compiles fine and seems to run fine, but its not printing out any packet informati...

Optional function parameters: Use default arguments (NULL) or overload the function?

I have a function that processes a given vector, but may also create such a vector itself if it is not given. I see two design choices for such a case, where a function parameter is optional: Make it a pointer and make it NULL by default: void foo(int i, std::vector<int>* optional = NULL) { if(optional == NULL){ optional = new...