c++

Learning java as a C++ programmer

Long story short: I'm looking for either a book or documentation/reference explaining basic java syntax and functionality from a C++ perspective. I don't need to know about design patterns, encapsulation, keywords such as 'static', etc. What I do want is to know what packages are, know about the import/extends keywords, mostly syntax r...

Overloaded member function pointer to template

Hi! I'm try to store member function pointers by templates like this. (This is a simplified version of my real code) template<class Arg1> void connect(void (T::*f)(Arg1)) { //Do some stuff } template<class Arg1> void connect(void (T::*f)()) { //Do some stuff } class GApp { public: void foo() {} void foo(double ...

How does function-level linking deal with variables declared at file level?

As I understand function-level linking builds (explicitly or not) a graph of all possible calls and only includes the reachable functions' code into the produced binary. But how does it deal with variables declared at file level? Say I have MyClass GlobalVariable; static MyClass StaticGlobalVariable; in some file that contains only t...

How does visual studio know which cpp files to rebuild when an include file is changed?

In some of my VS 2005 projects, when I change an include file some of the cpp files are not rebuilt, even though they have a simple #include line in them. Is this a known bug, or something strange about the projects? Is there any information about how VS works out the dependencies and can I view the files for that? btw I did try some ...

What is the simplest way to write a timer in C/C++?

What is the simplest way to write a timer in C/C++? Hi, What is the simplest way to write a timer, say in C/C++? Previously I used a for loop and a do-while loop. I used the for loop as a counter and the do-while loop as a comparison for "end of time". The program worked as I wanted it to, but consumed too much system resources. I'm l...

pthread_cond_timedwait linking error with clock_gettime on Solaris 10

Hello, I have a bit of code which used pthread_cond_wait which looks like this: struct timespec ts; clock_getttime(CLOCK_REALTIME, &timS); ts.tv_sec += delay; pthread_mutex_lock(&a_mutex); pthread_cond_timedwait(&thread_cond, &a_mutex,&timS); pthread_mutex_unlock(&a_mutex); But I get a linker error on compilation, undefine...

Name resolution in templates

I was reading about the template name resolution here. Just to get the feel of the things I replicated the code like this: void f (char c) { std::cout<<"f(char)\n"; } template <class T> void g(T t) { f(1); f(T(1)); f(t); d++; } double d; void f(int n) { std::cout<<"f(int)\n"; } void test() { std::cout<<"Fir...

Load Excel data into Linux / wxWidgets C++ application?

I'm using wxWidgets to write cross-plafrom applications. In one of applications I need to be able to load data from Microsoft Excel (.xls) files, but I need this to work on Linux as well, so I assume I cannot use OLE or whatever technology is available on Windows. I see that there are many open source programs that can read excel files ...

How do I get the VS debugger to display the type name of an object member?

The Visual Studio autoexp.dat syntax allows you to display ‘the name of the most-derived type of the object’ with the 'special format' <,t>, which is very helpful if you have lots of derived types. From the syntax, I assumed that you could do the same thing for members, such as <member,t>, but when I try that the preview only shows ??? ...

How to Convert Address to Function Pointer to Call Method

Hi, I wanted to call Test1() Method Within WaitAndCallFunc() Function. Code: typedef void (*func)(); void StartTimer(void* pFuncAddr); void WaitAndCallFunc(void* pPtr); void WaitAndCallFunc(void* pPtr) { int i = 0; int nWaitTime = 3; while(1) { Sleep(1000); // I want pPtr to call Test1 Function; if(i =...

getsockopt() returns EINPROGRESS in non blocking connect()+select() flow [closed]

Update: My BAD. The error I am getting is ECONNREFUSED and not EINPROGRESS. After I had checked the %error% variable and found that it is greater than 0, I printfed errno instead of %error%. Of course errno is EINPROGRESS because it value didn't change since the call to connect(). Question answered. Thanks folks. I am using the the...

start exe as non admin from admin exe

Hi, When my app updates it needs admin rights and pops the uac prompt up and this is all good. However when it restarts it self its still in admin mode and thus every thing it does has admin rights. The problem comes when the next time the app is started its a normal user and thus cant read any of the files that where made before. How ...

reading bytes directly from RAM C++

Can anyone explain the following behaviour to a relative newbie... const char cInputFilenameAndPath[] = "W:\\testerfile.bin"; int filesize = 4584; char * fileinrampointer; fileinrampointer = (char*) malloc(filesize); ifstream fsInputFileStream; fsInputFileStream.open(cInputFilenameAndPath, fstream::in | fstream::binary); fsInputFileS...

How can web technology be used for a C++ application GUI?

Can web technologies be used for a desktop application written in a traditional language like C++? I'd guess that they can, though I've not been able to find any evidence of this. I understand Adobe Air can make desktop apps using Flash, but it uses web languages like php etc. What I'd like to do is to be able to build my GUI elements - ...

C++ runtime debugging (diagnostic strategies and constructs)

I'm planning to add extensive diagnostics into my software. Right now I'm thinking about overall strategy of how to do this, because adding such code simply ad hoc can result in serious mess. Do you have any experience in this? I want to monitor: How intensively objects from selected subset are created. How intensively selected metho...

A std::map that keep track of the order of insertion?

I currently have a std::map<std::string,int> that stores an integer value to an unique string identifier, and I do look up with the string. It does mostly what I want, except for that it does not keep track of the insertion order. So when I iterate the the map to print out the values, they are sorted according to the string; but I want ...

What makes Scala's operator overloading "good", but C++'s "bad"?

Operator overloading in C++ is considered by many to be A Bad Thing(tm), and a mistake not to be repeated in newer languages. Certainly, it was one feature specifically dropped when designing Java. Now that I've started reading up on Scala, I find that it has what looks very much like operator overloading (although technically it doesn'...

Eclipse-CDT: Whats the best way to add a custom build step?

I have a file in my project which I need to compile using an external tool, and the output of that is a pair of .c and .h files. Whats the best way to integrate this into my Eclipse-CDT build? Ideally I can reference the external tool using a relative path Ideally Eclipse will know if I change this file that it needs to re-run the ext...

Forward "Pre-declaring" a Class in C++

Hi all! I have a situaion in which I want to declare a class member function returning a type that depends on the class itself. Let me give you an example: class Substring { private: string the_substring_; public: // (...) static SubstringTree getAllSubstring(string main_string, int min_size); }; And Su...

Universal less<> for pointers in C++ standard

Many times I needed a set of pointers. Every time that happens, I end up writing a less<> implementation for a pointer type - cast two pointers to size_t and compare the results. My question is - is that available in the standard? I could not find anything like that. Seems like common enough case... Update: it seems that the upcoming s...