c++

Finding statement pattern in c++ file

I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR) ods() where ods() is a class that behaves similarly to cout, and VERBOSITY_SETTING is a global variable. There are a few of these for different verbosity settings, and it allows the code to look something like this: if (someErrorCon...

how to set pointer to a memory to NULL using memset?

Hi, I have a structure typedef struct my_s { int x; ... } my_T; my_t * p_my_t; I want to set the address of p_my_t to NULL, tried: memset (&p_my_t, 0, sizeof(my_t*)) This does not look right, what is the correct way of doing this? appreciate it... Amendment to question - asking a radically more complex question: Thank...

Extending a C++ application with C# plugins

I have a C++ Windows application that can be extended by writing C++ plugins, using an API that is exposed by the application. There is also one plugin that translates the C++ API to Python (e.g. plugins can be written in Python). I want to allow users to write plugins in C# in addition to C++ and Python. Since I'm not very familiar wit...

Is the sizeof(some pointer) always equal to four?

For example: sizeof(char*) returns 4. As does int*, long long*, everything that I've tried. Are there any exceptions to this? ...

Help with the ifstream function in C++

I've read a lot of tutorials and can not really find anything comprehensive on this subject. I had written the following code to do one function: #include <fstream> #include <string> #include <iostream> using namespace std; ifstream ReadFile( ifstream& openInputFile, string& sLine, int& chgLine ); int main() { int chgLine; ...

Why are c/c++ floating point types so oddly named?

C++ offers three floating point types: float, double, and long double. I infrequently use floating-point in my code, but when I do, I'm always caught out by warnings on innocuous lines like float PiForSquares = 4.0; The problem is that the literal 4.0 is a double, not a float - Which is irritating. For integer types, we have short in...

Store huge std::map, mostly on disk

I've got a C++ program that's likely to generate a HUGE amount of data -- billions of binary records of varying sizes, most probably less than 256 bytes but a few stretching to several K. Most of the records will seldom be looked at by the program after they're created, but some will be accessed and modified regularly. There's no way to ...

Forward declare method pointer

I am using the pimpl idiom and want to reference one of the methods of the forward declared class. Below isn't exactly what I'm doing but uses the same concepts. template< typename Class, void (Class::*Method)(void) > struct Call { Call( Class* c ) : m_c(c) { } void operator()( void ) { (m_c->*Method)(); } ...

How do I link PDCurses to a C++ application on Windows?

I'm building a C++ application and need to use PDCurses on Windows. I'm compiling with VC++ from MS VS 2005 and I'm getting a link error. error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function __get_key_count There are 11 errors all with the same error code and different symbols. The missing symbols...

Design question for abstract base class?

Have a interface class abc { public: virtual int foo() = 0; ... } class concrete1: public abc { public: int foo() { .. } class concrete2 : public abc { public: int foo() { .. } } Now in my main program I need to construct classes based upon a value of a variable abc *a; if (var == 1) a = new concrete1(); else a...

Inadvertent use of = instead of ==

It seems that if (x=y) { .... } instead of if (x==y) { ... } is a root of many evils. Why don't all compilers mark it as error instead of a configurable warning? I'm interested in finding out cases where the construct if (x=y) is useful. ...

Best compiler warning level for C/C++ compilers?

What compiler warning level do you recommend for different C/C++ compilers? gcc and g++ will let you get away with a lot on the default level. I find the best warning level for me is '-Wall'. And I always try to remove fix the code for the warnings it generates. (Even the silly ones about using parenthesis for logical precedence rule...

Pointer class assistance

I'm writing a sparse matrix class in C++ in which every row and column are arrays of linked lists from a class I created (aptly named: LinkedList). I want to write a class that is a "smart" pointer to one cell in this matrix. In that class, let say LIPointer, I will implement a ++ operator function for moving in the linked lists of the...

C++ variable with same name, context : global and private,

In the following code, g++ gives this error : 1.cpp: In member function void W::test()': 1.cpp:6: error: int F::glob' is private 1.cpp:19: error: within this context But, shouldn't the globally declared variable 'glob' be used here, instead of the "private" "glob"? #include <iostream.h> int glob; class F { int g...

c++ network credentials

Hi, I have web service in my MFC Application and I want to write something like: WebService * ws = new WebService(); ws->Credentials = new NetworkCredentials(user, pass); I could not find Credentials class in MFC. Is there such class in MFC? ...

How often do you check for an exception in a C++ new instruction?

I just started reading Effective C++ today and got to the point where the author talks about the operator new. The book explains very well how you can catch (with various degrees of elegance) the std::bad_alloc exception that the operator new can raise if you run out of memory. My question is: How often do you check for the case when t...

what is the purpose and return type of the __builtin_offsetof operator?

What is the purpose of the __builtin_offsetof operator (or _FOFF operator in Symbian) in C++? In addition what does it return? Pointer? Number of bytes? ...

How do you retrieve the original location of a mounted path?

In C++, how can I retrieve the location of a mounted drive? for example, if I have mounted drive s: to c:\temp (using subst in the command line) "subst c:\temp s:" how can I get "c:\temp" by passing "s:" I would also like to know how can it be done for a network drive. (if s: is mounted to "\MyComputer\Hello", then I want to retrieve "...

How can I pass a class member function as a callback?

Hi, I'm using an API that requires me to pass a function pointer as a callback. I'm trying to use this API from my class but I'm getting compilation errors. Here is what I did from my constructor: m_cRedundencyManager->Init(this->RedundencyManagerCallBack); This doesn't compile - I get the following error: Error 8 error C3867...

How to fetch HTML in C/C++

How to fetch HTML in C or C++? with Sockets. Can you give me a Example code pls? NOTE - I originally closed this, but reopened. To the poster - Please see: http://stackoverflow.com/questions/400688/fetch-web-page-in-c and http://stackoverflow.com/questions/389069/programmatically-reading-a-web-page#389074 ...