c++

Enumerate shared folders on Windows with low privileges

Using C++ (VS2008) I need to be able to enumerate all shared folders on the current machine and get or construct the local and remote names. We've been using NetShareEnum for this fairly successfully, but have hit a problem where we need to run with a user account with low privileges. To get the local path using NetShareEnum we need to...

inline vs __inline vs __inline__ vs __forceinline?

What are the differences between these four inline (key)words? inline, __inline, __inline__, __forceinline. ...

Splitting a double vector into equal parts

Greetings, Any input on a way to divide a std::vector into two equal parts ? I need to find the smallest possible difference between |part1 - part2|. This is how I'm doing it now, but from what you can probably tell it will yield a non-optimal split in some cases. auto mid = std::find_if(prim, ultim, [&](double temp) -> bool { if(...

Visual Studio 2010 library linking order

How do you specify, in Visual Studio 2010, the order in which library files should be linked? I have a project that links against libexpat and against another library. This library (not under my control) seems to also include libexpat. The problem is that 'we' use a different version of the library (XML_UNICODE vs not). In Visual Studio...

How to cin Space in c++?

Say we have a code: int main() { char a[10]; for(int i = 0; i < 10; i++) { cin>>a[i]; if(a[i] == ' ') cout<<"It is a space!!!"<<endl; } return 0; } How to cin a Space symbol from standard input? If you write space, program ignores! :( Is there any combination of symbols (e.g. '\s' or something li...

C++ Any way to store different templated object into the same container

Is there any hack I could use to do this: template <class TYPE> class Hello { TYPE _var; }; I would like a way to store Hello<int> intHello and Hello<char*> charHello into the same Container such as a Queue / List. ...

C++ Virtual Constructor, without clone()

I want to perform "deep copies" of an STL container of pointers to polymorphic classes. I know about the Prototype design pattern, implemented by means of the Virtual Ctor Idiom, as explained in the C++ FAQ Lite, Item 20.8. It is simple and straightforward: struct ABC // Abstract Base Class { virtual ~ABC() {} virtual ABC * clo...

What is a reference variable in C++?

Can someone give me a brief definition of a reference variable in C++? ...

Linking Libraries with Duplicate Class Names using GCC

Is there a way for GCC to produce a warning while linking libraries that contain classes with the same name? For example Port.h class Port { public: std::string me(); }; Port.cpp #include "Port.h" std::string Port::me() { return "Port"; } FakePort.h class Port { public: std::string me(); }; FakePort.cpp #include "FakePort....

Why is std::numeric_limits<T>::max() a function?

In the standard library of C++ the value std::numeric_limits<T>::max() is specified as a function. Further properties of a specific type are given as constants (like std::numeric_limits<T>::is_signed). All constants that are of type T are given as functions, whereas all other constants are given as, well, constant values. Whats the rati...

Porting Windows C++ to Standard (Linux) C++ - WSAGetLastError()

I am currently porting some Windows mobile C++ code to standard C++. So I am trying to find alternatives for windows specific functions. I have had very little luck in finding a standard C++ function that can help me replace the WSAGetLastError() windows specific function. WSAGetLastError() returns error numbers for errors that occur ...

Using WINAPI ReadConsole

I am trying to use the WINAPI ReadConsole() to wait for any keypress at the end of my Win32 console application. CONSOLE_READCONSOLE_CONTROL tControl; char pStr[65536]; DWORD dwBufLen = 1; DWORD dwCtl; tControl_c.nLength = sizeof( CONSOLE_READCONSOLE_CONTROL ); tControl_c.nInitialChars = 0; tControl_c.dwControlKeyState = 0; tControl_c....

What elegant method callback design should be used ?

Hi, I'm surprised this question wasn't asked before on SO (well, at least I couldn't find it). Have you ever designed a method-callback pattern (something like a "pointer" to a class method) in C++ and, if so, how did you do it ? I know a method is just a regular function with some hidden this parameter to serve as a context and I hav...

writing a single line of a file in C++ into two different arrays

suppose a text file has 11001100 11001101 and i open the text file and take the input from the file as pt[0]=11001100, pt[1]=11001101.. but if i take the input from file as in>>pt it wont put it in two different arrays which is obvious but it takes the whole line . Thus I have to take another for loop and traverse through the whole...

What exactly do "IB" and "UB" mean?

I've seen the terms "IB" and "UB" used several times, particularly in the context of C++. I've tried googling them, but apparently those two-letter combinations see a lot of use. :P So, i ask you...what do they mean, if they're said like it's a bad thing? ...

Working with operator[] and operator=

Given a simple class that overloads the '[ ]' operator: class A { public: int operator[](int p_index) { return a[p_index]; } private: int a[5]; }; I would like to accomplish the following: void main() { A Aobject; Aobject[0] = 1; // Problem here } How can I overload the assignment '=' operator in...

Programmatically create and launch and RDP session (without gui)

Hello, I'd like to know if there is a way to create and launch a Remote Desktop Session on a Windows Server programmatically. I'm trying to make an automatic tool to create Local Users and then launch the associate RDP session. I've already made LocalUser creation and adding them to Remote Desktop Users (using net.exe). But I'm struck ...

Problem creating an array of objects C++

I have a class and I want to create an array of a number instances, specifically a matrix class: class Matrix { public: Matrix(int sizeX, int sizeY); Matrix(); ~Matrix(); ....//omiting the rest here private: int dx, dy; float **p void allocArrays() { assert(dx>0); assert(dy>0); p =...

Getting value from pointer

Hi, I'm having problem getting the value from a pointer. I have the following code in C++: void* Nodo::readArray(VarHash& var, string varName, int posicion, float& d) { //some code before... void* res; float num = bit.getFloatFromArray(arregloTemp); //THIS FUNCTION RETURN A FLOAT AND IT'S OK cout << "NUMBER ...

How to pass array to function without variable instantiation, in C++

Can I do this in C++ (if yes, what is the syntax?): void func(string* strs) { // do something } func({"abc", "cde"}); I want to pass an array to function, without instantiating it as a variable. Thanks for suggestions. ...