c++

operator () overload with template C++

I have a simple class for which I want to overload operator as below class MyClass { public: int first; template <typename T> T operator () () const { return first; } }; And the somewhere else I have MyClass obj; int i = obj(); // This gives me an error saying could not deduce // template argum...

Can operators be used as functions? (C++)

This is similar to another question I've asked, but, I've created an expression class that works like so: expression<int, int> exp(10, 11, GreaterThan); //expression<typename T, typename U> exp(T val1, U val2, oper op); //where oper is a pointer to bool function(T, U) where GreaterThan is a previously defined function. And I am wonde...

Object Oriented C++ library for ssh and scp

Is there any Object Oriented C++ library for ssh and scp. BSD license would be preferred. I could find libssh and libssh2. But these are all procedural. ...

C++ basic constructors/vectors problem (1 constructor, 2 destructors)

Question is probably pretty basic, but can't find out what's wrong (and it leads to huge of memleaks in my app): class MyClass { public: MyClass() { cout << "constructor();\n"; }; MyClass operator= (const MyClass& b){ cout << "operator=;\n"; return MyClass(); }; ~MyClass() { cout << "destructor();\n"; }; }; ma...

reading data from files, file name as input

Hey, I am writing a program which reads data from different files, which are given as input strings, and stores them into a vector of vectors. The problem I am not able to debug the loop which reads different files. I have closed the ifstream object, cleared the string using empty function... but still it just terminates when i give seco...

how to query if(T==int) with template class

When I'm writing a function in a template class how can I find out what my T is? e.g. template <typename T> ostream& operator << (ostream &out,Vector<T>& vec) { if (typename T == int) } How can I write the above if statement so it works? ...

using checkTokenMemberShip return always true even if the process user is not administrator

the following is the code I'm using (copied from msdn) but even when the the pocess user is not a local admin it returns as if it is any ideas? BOOL IsUserAdmin(VOID) /*++ Routine Description: This routine returns TRUE if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyo...

How to write an unkillable process for Windows?

I'm looking for a way to write an application. I use Visual C++ 6.0. I need to prevent the user from closing this process via task manager. ...

Error C2228 when constructing boost::function object in constructor argument list

The code below does not compile in Visual C++ 2005. class SomeClass { public: boost::function<void()> func; SomeClass(boost::function<void()> &func): func(func) { } }; void someFunc() { std::cout << "someFunc" << std::endl; } int main() { SomeClass sc(boost::function<void()>(&someFunc)); sc.func(); // error C2228: ...

How to install SDL library in Visual C++ 2008?

Hey, How to install SDL library in VISUAL C++ 2008? I I am looking for a tutorial how to install, but I found nothing good :(( please help me?, sorry for bad english. Thanks :)) ...

How to get an 'array of strings' as a function's return type?

String[] decode(String message) Above is an example. I need to get 2 strings s1 and s2 as the return values for the decode function. How should I proceed? ...

Write to registry in Windows Vista...

Hello, I am trying to write to the registry from my application, but when I do I get access denied. Of course, it works if i run the app as Administrator. However, with my applcation, it is not initiated by the user. It start automatically. So, the question is, how do i read/write to my own registry key from the C++ app? Thanks for...

__vftptr is NULL

We received crash dump from customer site. I see that in one of the structures o nstack __vfptr is NUL. Does it always point to problematic condition (memeory overrun, deleting object twice...) or is there case where this pointer can be null. ...

How to access the Java method in a C++ application

Just a simple doubt: Is it possible to call a java function from c/c++ ? ...

How to set up Win32 tooltips control with dynamic unicode text?

I am having some trouble provding a Win32 tooltips control with dynamic text in unicode format. I use the following code to set up the control: INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(INITCOMMONCONTROLSEX); icc.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx( HWND hwnd_tip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP |...

importance of freeing memory?

Possible Duplicate: What REALLY happens when you dont free after malloc? When ending a program in C/C++, you have to clean up by freeing pointers. What happens if you doesn't free the memory, like if you have a pointer to an int and doesn't delete it when ending the program? Is the memory still used and can only be freed by rest...

working with fstream files in overflow chaining in c++

Hello, I have a file that I want to read and write to a binary file using records. In the beginning I have an empty file and I want to add new record, but when I use the seekp function, then the location is at (-1) is it ok? Because when I check, I see that it hasnt written anything to the file. See code: void Library::addBook(Book ne...

How does the C++ runtime determine the type of a thrown exception?

If I do the following, how does the runtime determine the type of the thrown exception? Does it use RTTI for that? try { dostuff(); // throws something } catch(int e) { // .. } catch (const char * e) { // .. } catch (const myexceptiontype * e) { // .. } catch (myexceptiontype e) // is this the same as the previous handler? { /...

When should I make explicit use of the `this` pointer?

When should I explicitly write this->member in a method of a class? ...

Unable to get ATL Connection Points working...

I am trying to create a COM component using ATL, and I'd like to raise events for my VB client. I've found numerous tutorials, all of which seem to vary in details, and none of them appear to generate a working solution. Here is what I am doing: (Using Visual Studio 2008): Create a new ATL DLL Project. I've called it ATLEventTest. C...