question_id
int64
25
74.7M
answer_id
int64
332
74.7M
title
stringlengths
20
150
question
stringlengths
23
4.1k
answer
stringlengths
20
4.1k
1,149,594
1,149,705
get static int variable class name with typeid(*this).name for its own definition - C++
When I need to get the class name inside of one of its methods I just call: typeid(*this).name() (then I split the result into tokens and get the class name) Now I have to define a static member variable and need to get the class name for that. But I`m not in a method! So, I cannot use (*this). Initially, I thought I ...
I don't think it is directly possible to do what you want - as a static method doesn't get an object pointer it can't call typeid on it. You could create a temporary object in the static method and use that on typeid, but that pretty much goes against having it as a static method. Another solution (if you can guarante...
1,149,620
1,149,622
How to write to the Output window in Visual Studio?
Which function should I use to output text to the "Output" window in Visual Studio? I tried printf() but it doesn't show up.
OutputDebugString function will do it. example code void CClass::Output(const char* szFormat, ...) { char szBuff[1024]; va_list arg; va_start(arg, szFormat); _vsnprintf(szBuff, sizeof(szBuff), szFormat, arg); va_end(arg); OutputDebugString(szBuff); }
1,149,697
1,349,710
managed c++ find and replace syntax
I'm building an isapi filter that will grab any url requests with the prefix "http://localhost/" and redirect that url request to my message page "http://localhost/default.html." Here's the solution: if(urlString.Find("/") != -1) { urlString.Replace(urlString, "/default.html");
the answer is: if(urlString.Find("/") != -1) { urlString.Replace(urlString, "/default.html");
1,149,801
1,150,227
Check for update (compare remote XML file with a local variable)
I have an InnoSetup for my C# application. And I'd like the setup to check for updates before installing (to make sure the user always gets the latest version). To do this, I need a bit of C++ code to parse an xml file from a remote location (which contains a version string) and have a method return it. From InnoSetup ...
If you have access to the server side, it might be better to not use XML, just return version string. If you can't avoid XML, you should write your C++ code (if that's you question, I suggest using TinyXML), then create a dll export for a function returning the version string.
1,149,826
1,149,840
Get actual folder path
How I can get actual folder path where my program is without my exe file name in C++?
The following function will give you the application path: ::GetModuleFileName(NULL, szAppPath, MAX_PATH); Now to extract the folder, you need to find the last backslash: char szApplicationPath[MAX_PATH] = ""; ::GetModuleFileName(NULL, szApplicationPath, MAX_PATH); //Get the folder part CString strApplicationFolder;...
1,149,856
1,150,853
Choosing a 3D game engine
I want to start this as a hobby in developing a desktop game. I have found several engines, but I am not sure whether it does the initial job I am looking at. Initially I want to do the following: Create a figure (avatar), and let the user dress the avatar Load the avatar in the game In later stages, I want to deve...
I also recommend Ogre. Ogre can do this, it provides everything needed in regards of mesh and animation support, but not as a drop-in solution. You have to write lots of code for this to be done. For our project we implemented something like you do. The main character and any other character can be dressed with differe...
1,149,919
1,149,925
std::list<char> list_type to (char * data, int lenght)
I have some std::list<char> list_type Now I have to supply contents of the list as (char *data, int length). Is there convenient way to present list contents as pointer and length? Does <vector> has such interface? Thank you in advance.
You can do it with a vector, because its data is stored contiguously: std::vector<char> vec; char* data = &vec[0]; int length = static_cast<int>(vec.size()); For list, you have to copy the data to an array. Luckily, that too is fairly easy: std::list<char> list: int length = static_cast<int>(list.size()); char* data ...
1,149,929
1,150,180
How to add two numbers without using ++ or + or another arithmetic operator
How do I add two numbers without using ++ or + or any other arithmetic operator? It was a question asked a long time ago in some campus interview. Anyway, today someone asked a question regarding some bit-manipulations, and in answers a beautiful quide Stanford bit twiddling was referred. I spend some time studying it ...
This is something I have written a while ago for fun. It uses a two's complement representation and implements addition using repeated shifts with a carry bit, implementing other operators mostly in terms of addition. #include <stdlib.h> /* atoi() */ #include <stdio.h> /* (f)printf */ #include <assert.h> /* assert() *...
1,149,994
1,150,676
std::list, std::vector methods and malloc()
Working with stl:list and stl::vector types under interrupt handlers I want to avoid malloc() calls. The question: What is a best way to prevent malloc() calls in STL list and vector? Is it enough to create structure with predefined size and then avoid push/pop/erase calls? Thank you in advance
As a testimonial: we use two methods mentioned in other answers at my workplace: custom allocators: for our memory leak tracking system, our instrumenting profiler, and a few other systems, we preallocate and/or "pool" (see e.g. boost::pool) allocs using a provided Allocator -- usually for std::set or std::map, but th...
1,150,072
1,150,077
Install CDT Plug-In On Eclipse Ganymede
How i can install the CDT plug-in (that you can develop in C++ under Eclipse) in my Eclipse Ganymede, remember that I use Windows Vista. Thanks!
Use this official guide: http://wiki.eclipse.org/Getting_started_with_CDT_development
1,150,373
1,155,092
Compile the Python interpreter statically?
I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. libc.a not libc.so). I would also like to statically link all dynamic libraries that are part of the Python standard library. I k...
I found this (mainly concerning static compilation of Python modules): http://bytes.com/groups/python/23235-build-static-python-executable-linux Which describes a file used for configuration located here: <Python_Source>/Modules/Setup If this file isn't present, it can be created by copying: <Python_Source>/Modules...
1,150,464
1,150,750
msvcr90d.dll not found in debug mode
I found MSVCR90D.dll not found in debug mode with Visual C++ 2008 question but none of given answers really gives answer to the question. Most of them point to turning off incremental linking but don't explain the true cause of the error and how it can be fixed without turning off incremental linking. I'd like to menti...
Below is output from compiler. It's strange that running build the second time succeeds. However I suspect the problem might be due to this error with running mt.exe which is responsible for embedding information from manifest into executable... Generating Code... link /LIBPATH:"c:\Qt\4.5.2-vc\lib" /NOLOGO /DEBUG /MANI...
1,150,649
1,151,539
trouble deleting keys/values on STL hash_map when duplicate keys
I am using C++ hash_map to store some C-style string pairs. And all keys should be unique for this case... My problem is a serious memory leak when stress testing this over multiple runs. When none of these keys in the test are not identical, there is no memory leak. But with identical keys its a different story... Th...
You can change a value directly inside hash_map through iterator: ret = it->second; it->second = v; // end option 2 } It will be faster and safer solution. You can also try another hash_map method to erase by key, not by iterator: size_type erase(const key_type& k)
1,150,833
1,150,901
What did QWidget* QApplication::mainWidget() become in Qt4?
I am porting an application from Qt3 to Qt4, and need a Qt4 replacement for QApplication::mainWidget() which used to return the top-level widget in Qt3. Does anyone know how to do this in Qt4?
Technically, any widget initialized with NULL is a top level widget so QApplication shouldn't assume that one of them is better than another. The way I usually do it is to save a pointer to the "real" main widget somewhere, even a global variable or a singleton and reference it when needed.
1,151,358
1,151,367
Operator Overloading for Objects in Multiple Classes
So can you overload operators to handle objects in multiple classes (specifically private members.) For example if I wanted == to check if a private member in Class A is equal to objects in a vector in Class B. For example: bool Book::operator==(const Book& check){ return(((ISBN1 == check.ISBN1) && (ISBN2 == check.IS...
If you make operator friend or member of one class, it will be able to access its private members. To access privates of both, operator will have to be free standing friend of both. That is a bit unwieldy, so consider making public interface for interesting things instead. (suppressed all puns about accessing private ...
1,151,582
1,151,638
pthread function from a class
Let's say I have a class such as class c { // ... void *print(void *){ cout << "Hello"; } } And then I have a vector of c vector<c> classes; pthread_t t1; classes.push_back(c()); classes.push_back(c()); Now, I want to create a thread on c.print(); And the following is giving me the problem below: pthread_cre...
You can't do it the way you've written it because C++ class member functions have a hidden this parameter passed in. pthread_create() has no idea what value of this to use, so if you try to get around the compiler by casting the method to a function pointer of the appropriate type, you'll get a segmetnation fault. Yo...
1,151,680
1,151,740
C++ Auto Class Implementation in Editor
Much of my time spent developing C++ applications is wasted implementing class definitions. By that I mean the prototyping of classes then creating their respective implementations. For example: #ifndef FOO_H #define FOO_H class Foo { public: Foo (const X& x, const Y& Y); ~Foo (); void PerformXYZ (int Count)...
In Visual Studio there are tools to add functions and variable. Tools automates the process in question. But I never use them :) In the Visual Assist X there is the feature that helps to add implementation for methods. It is the best solution.
1,151,777
1,151,793
Fast Bitwise Question in C++
I'm looking for a fast way to setup a method of returning a bitmask based on a number. Basically, 4 one bits need to be emitted pre number input. Here's a good idea of what I mean: foo(1); // returns 0x000F foo(2); // returns 0x00FF foo(3); // returns 0x0FFF foo(4); // returns 0xFFFF I could just use a big switch state...
How about something like: template <typename T> T foo(unsigned short length) { return (T(1) << (length * 4)) - 1; }
1,151,787
1,152,672
Is there any automated way to implement post-constructor and pre-destructor virtual method calls?
Due to the well-known issues with calling virtual methods from inside constructors and destructors, I commonly end up with classes that need a final-setup method to be called just after their constructor, and a pre-teardown method to be called just before their destructor, like this: MyObject * obj = new MyObject; obj-...
The main problem with adding post-constructors to C++ is that nobody has yet established how to deal with post-post-constructors, post-post-post-constructors, etc. The underlying theory is that objects have invariants. This invariant is established by the constructor. Once it has been established, methods of that clas...
1,151,849
1,151,955
Why does QGraphicsItem::scenePos() keep returning (0,0)
I have been toying with this piece of code: QGraphicsLineItem * anotherLine = this->addLine(50,50, 100, 100); qDebug() << anotherLine->scenePos(); QGraphicsLineItem * anotherLine2 = this->addLine(80,10, 300, 300); qDebug() << anotherLine2->scenePos(); Where the this pointer refers to a QGraphicsScene. In both cases, ...
After reading the QT 4.5 documentation carefully on addLine, I realize what I have been doing wrong. According to the doc: Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0) So if I specify addLine(50,50, 100, 100), I am actually modifying its local item coord...
1,152,000
1,152,003
stringstream extraction not working
I seem to be having a problem with extracting data from a stringstream. The start of my extraction seems to be missing the first two characters. I have something similar to the following code: std::stringstream ss( std::stringstream::in | std::stringstream::out ); bool bValid; double dValue; ...
Try: // add data to stream ss << bValid << " "; ss << dValue << " "; ss << dTime << " ";
1,152,048
1,158,194
How to calculate determinant matrix with lapack++ (2.5+)
What is the best (fastest) way to calculate the determinant of a (non symmetric, squared) LaMatGenDouble matrix with the lapack++ library?
One way to calculate the determinant is using the LU decomposition: LaVectorLongInt pivots(A.cols()); LUFactorizeIP(A, pivots); double detA = 1; for (int i = 0; i < A.cols(); ++i) detA *= A(i, i); Warning, A will change, so making a copy is probably advised.
1,152,224
1,152,274
Please explain two lines to me
typedef vector<double>::size_type vec_sz; vec_sz size = homework.size();
The first line creates an alias of the vector<double>::size_type type. The typedef keyword is often used to make "new" data types names that are often shorter than the original, or have a clearer name for the given application. The second line should be pretty self-explanatory after that.
1,152,333
1,152,396
Force compiler to not optimize side-effect-less statements
I was reading some old game programming books and as some of you might know, back in that day it was usually faster to do bit hacks than do things the standard way. (Converting float to int, mask sign bit, convert back for absolute value, instead of just calling fabs(), for example) Nowadays is almost always better to ...
Compilers are unfortunately allowed to optimise as much as they like, even without any explicit switches, if the code behaves as if no optimisation takes place. However, you can often trick them into not doing so if you indicate that value might be used later, so I would change your code to: int float_to_int(float f) ...
1,152,470
1,152,485
vector -> Usage of member functions begin() and end() vs the operator[]
While using the vector why do we sometime use the operator[] like homework[mid] but other times use homework.begin(). Also, homework.end() not homework[end], but that's like begin. Is it just accessing the elements differently? It's more confusing this way, don't you agree?
vector::operator[] retrieves the Nth element of the vector. Such an operator is defined only for select STL container classes. vector.end() is a method returning an iterator. Iterators are special entities for working with STL containers, vector included. vector::end() points onto the element immediately following the ...
1,152,497
1,152,504
Is there a boost smart pointer class that can be configured not to delete at destruction?
I have a list of smart pointers. I want some of these smart pointers to act as regular pointers, meaning they are simply a reference to an instance and are not involved in its deallocation. They might for example point to instances allocated on the stack. The other smart pointers in the list should act as regular boost...
One constructor for shared_ptr takes the destructor method, and you can pass in an empty functor. Using Custom Deallocator in boost::shared_ptr (You want just an empty function.)
1,152,511
1,215,807
Any reason to overload global new and delete?
Unless you're programming parts of an OS or an embedded system are there any reasons to do so? I can imagine that for some particular classes that are created and destroyed frequently overloading memory management functions or introducing a pool of objects might lower the overhead, but doing these things globally? Addi...
We overload the global new and delete operators where I work for many reasons: pooling all small allocations -- decreases overhead, decreases fragmentation, can increase performance for small-alloc-heavy apps framing allocations with a known lifetime -- ignore all the frees until the very end of this period, then free...
1,152,828
1,153,013
doxygen: how do I document \enum values out-of-line?
To be precise: I know how to dox enums at the point of declaration, I want to dox them out-of-line instead. I want to keep the header file free of doxygen comments; they're all in the .cpp file. This is not a problem for functions, classes, typedefs and so on. I can also document the enum itself like this: /*! \enum ...
You need to use \var according to the docs
1,152,958
3,145,027
What is a "nearly-empty" class?
Compile the following class class Interface { virtual void doIt() = 0; virtual ~Interface() = 0; }; inline Interface::~Interface() {} using gcc -fdump-class-hierarchy. gcc emits Class Interface size=4 align=4 base size=4 base align=4 Interface (0x1a779c0) 0 nearly-empty vptr=((& Interface::_ZTV9Interfa...
The C++ ABI provides a definition of "nearly empty" classes and an interesting discussion of how they affect vtable construction: A class that contains a virtual pointer, but no other data except (possibly) virtual bases. In particular, it: has no non-static data members other than zero-width bitfields, has no direct...
1,153,052
1,153,262
How to programmatically get the resolution of a window and that of the system in Linux?
I'm trying to get the resolution of the screen as well as the resolution of a specific window (in which a program is running) on Linux system. I don't need to modify the resolution, I only need the current values. As far as I know, we can call some system functions to do so on Windows, how can we do that on Linux, pref...
In X11, you'd need to call the Xlib's XGetWindowAttributes to get the various window info, including the size and position relative to parent. For an example of how it is used, you can google for 'xwininfo.c'. That said, probably you are going to use some more highlevel framework to do your window programming - and the...
1,153,064
1,153,143
Memory Management on Objects in a C++ Collection
I have a map that relates integers to vectors (of objects). These vectors represent a set of tasks to perform. In order to reduce the amount of copying going on while using this map and vector I've set them up to make use of pointers. std::map<int, std::vector<MyObject *> *> myMap; During initialization of the class...
I agree the use of smart pointers is a good way to go, but there are at least two alternatives: a) Copying may not be as expensive as you think it is. Try implementing a map of values std::map<int, std::vector<MyObject>> myMap; b) Replace the vector with a class of your own that wraps the vector. In that classes destr...
1,153,090
1,153,130
How to detect that a given PE file (exe or dll) is 64 bit or 32 bit
I need to detect whether a given .dll or .exe file is 32 bit or 64 bit At the moment I have only one solution: read the PE Header from the specified file and take the 'Machine' field from there. ( Specification: Microsoft Portable Executable and Common Object File Format Specification (.docx file) at section "3.3. COFF...
GetBinaryType(...) returns SCS_32BIT_BINARY for a 32-bit Windows-based application and SCS_64BIT_BINARY for a 64-bit Windows-based application.
1,153,101
1,153,116
compiling c++ with gcc/g++ compiler
I'm new to c++ and i want to compile my testprogram . i have now 3 files "main.cpp" "parse.cpp" "parse.h" how can i compile it with one command?
Compile them both at the same time and place result in a.out $ g++ file.cpp other.cpp Compile them both at the same time and place results in prog2 $ g++ file.cpp other.cpp -o prog2 Compile each separately and then link them into a.out $ g++ -c file.cpp $ g++ -c other.cpp $ g++ file.o other.o Compile each separately...
1,153,209
1,153,236
Why does Qt include empty class definitions of existing classes in the header files?
I am reading through the examples on the Qt page and am wondering why they add references to already existing classes in their code example: #ifndef HTTPWINDOW_H #define HTTPWINDOW_H #include <QDialog> class QFile; class QHttp; class QHttpResponseHeader; class QLabel; class QLineEdit; class QProgressDialog; class QPu...
Those are forward declarations. Using them can (in some cases) obviate the need to #include the relevant header files, thus speeding up compilation. The Standard C++ library does something similar with the <iosfwd> header.
1,153,362
1,555,933
Using Common Header Files in eVC++ 3
I'm learning C++ and i have the eVT(eMbedded Visual Tools) installed in my computer, because of the eVB 3(eMbedded Visual Basic) for my VB pocket programs, but i'm learning C++, then i want to use the eVC++ 3 for develop some command line aplications, then only to test i created an HelloWorld aplication, just for test,...
Recently i see some eVC++ example and as i can see, eVC++(remember: Plus Plus) only uses C(Without ++) code.
1,153,501
1,153,629
Java solution for C++ style compiler directive
I have a Java array: String[] myArray = {"1", "2"}; Depending on a condition that is known at compile time I would like to assign different values: String[] myArray = {"A", "B", "C"}; In C++ I would use something like #ifdef ABC // ABC stuff here #else // 123 stuff here #endif but what to do in Java?
class Foo { static final boolean ABC = true; public void someMehod() { if (ABC) { // #ifdef ABC } else { // #else } // #endif } } since ABC is both static and final the compiler evaluates it at compile-time, effectively acting like a pre-processor.
1,153,548
1,153,585
minimum double value in C/C++
Is there a standard and/or portable way to represent the smallest negative value (e.g. to use negative infinity) in a C(++) program? DBL_MIN in float.h is the smallest positive number.
-DBL_MAX in ANSI C, which is defined in float.h.
1,153,900
1,154,009
Unresolved External Symbol
Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I fix it? I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. I have the .lib files linked in and everything has been going smoothly so fa...
The missing symbol is __imp__htonl@4, which is a C++ mangled name for htonl, which is a function that converts a long value from host to network order. The @4 is used to mangle the input parameters and is part of C++ support for overloaded functions to allow the linker to resolve the right function w/o name collisions...
1,153,986
1,154,004
Using VB for Artificial Intelligence
Do you think VB is a good language for AI? I originally did AI using mainly Lisp and C/C++ when performance was needed, but recently have been doing some VB programming. VB has the following advantages: 1. Good debugger (essential!) 2. Good inspector (watch facility) 3. Easy syntax (Intellisense comparable to structure...
Which VB are you talking about here? If you're talking VB.NET then yes, and no.. I would suggest C# or maybe F#.. F# is a functional language and hence is generally better suited for many of the patterns you'll be dealing with when programming AI. The newer versions of C# also have support for language features such as...
1,154,187
1,154,199
USB Communication API
Is there a decent USB communication API? Preferably cross-platform (Linux if not, I guess) I don't have a specific use in mind, I just want to learn about using the USB ports for future electronics projects. I realize this is very general, I'll try to refine the question as the answers point me in the right direction. ...
libusb should work for you .. cross platform, user-space USB tools.
1,154,212
1,154,683
How could I print the contents of any container in a generic way?
I am trying to write a piece of code for fun using C++ templates. #include <iostream> #include <vector> template <class Container> std::ostream& operator<<(std::ostream& o, const Container& container) { typename Container::const_iterator beg = container.begin(); o << "["; // 1 while(beg != container.end(...
You can restrict your operator<< to only apply to templated containers by specifying that the Container template parameter is itself templated. Since the C++ std containers also have an allocator template parameter you also have to include this as a template parameter of Container. template < typename T , templ...
1,154,221
1,154,296
Why are doubles added incorrectly in a specific Visual Studio 2008 project?
Trying to port java code to C++ I've stumbled over some weird behaviour. I can't get double addition to work (even though compiler option /fp:strict which means "correct" floating point math is set in Visual Studio 2008). double a = 0.4; /* a: 0.40000000000000002, correct */ double b = 0.0 + 0.4; /* b: 0.4000000059604...
The only thing I can think of is perhaps you are linking against a library or DLL which has modified the CPU precision via the control word. Have you tried calling _fpreset() from float.h before the problematic computation?
1,154,447
1,155,711
Is there an operating system API wrapper library for c++?
Does sombebody know a C++ library for accessing different operating system APIs? I'm thinking about a wrapper to access OS specific functions. Something like: osAPI.MessageBox(); // calls MessageBox() in Win32, equivalent in Mac OS Linux etc... Since I think it's hard to realize this for different OSes for now it ...
Boost offers libraries for networking (Boost.Asio), threads (Boost.Thread), time, dates, file system traversal, shared memory, memory mapped files, etc. ACE also has abstractions for networking, threads, time, file system stuff, shared memory, etc. AFAIK, neither has GUI abstractions or DB abstractions either. Others h...
1,154,593
1,154,669
String memory management during the assignment stored in the map
I have a string and I would like to put a reference to that string into a map. string m_tmp; map<pair<string, string>, string&> m; m[pair<string, string>("Foo","Bar")]= m_tmp; then, I change the m_tmp; m_tmp="DFDFD"; Will the map (on all conforming platforms) still reference m_tmp with a new value? According to the d...
Why dont you do this instead: map<pair<string, string>, shared_ptr<string> > m; Looks safer to me.
1,154,618
1,154,717
line drawing routine
How to optimize this line drawing routine ? Will memcpy work faster ? void ScreenDriver::HorizontalLine(int wXStart, int wXEnd, int wYPos, COLORVAL Color, int wWidth) { int iLen = wXEnd - wXStart + 1; if (iLen <= 0) { return; } while(wWidth-- > 0) { COLORVAL *Put = mpScanPoi...
I think you mean to say "memset" instead of "memcpy". Replacing this bit of the code: while (iLen--) { *Put++ = Color; } with memset(Put, Color, iLen); could be faster but so much depends on your target CPU, memory architecture and the typical values of iLen encountered. It's not likely to be a big win, but if ...
1,154,795
1,154,829
Kill self if hWnd doesn't exist
I have a c++ console application that launches another application and communicates with it via com. I have the spawned window's hWnd and I want the console app to kill itself if the COM app is no longer open. How could I go about doing this?
Since you are already communicating between the applications, you should set up a signal, when the window is closed it sends a 'I'm dead' message over to the console App. Your console app can then close appropriately. If you want to do this by checking the hWnd, you could simply use the 'IsWindow()' function which will...
1,154,974
1,163,708
C++0x will no longer have concepts. Opinions? How will this affect you?
At the July 2009 C++0x meeting in Frankfurt, it was decided to remove concepts from C++0x. Personally, I am disappointed but I'd rather have an implementable C++0x than no C++0x. They said they will be added at a later date. What are your opinions on this decision/issue? How will it affect you?
Personally I'm not too unhappy of the removal as the purpose of concepts were to mainly improve compile time error messages, as Jeremy Siek, one of the co-authors of the Concepts proposal, writes (http://lambda-the-ultimate.org/node/3518#comment-50071): While the Concepts proposal was not perfect (can any extension ...
1,154,991
1,158,071
Load binary file using fstream
I'm trying to load binary file using fstream in the following way: #include <iostream> #include <fstream> #include <iterator> #include <vector> using namespace std; int main() { basic_fstream<uint32_t> file( "somefile.dat", ios::in|ios::binary ); vector<uint32_t> buffer; buffer.assign( istream_iterator<u...
istream_iterator wants basic_istream as argument. It is impossible to overload operator>> inside basic_istream class. Defining global operator>> will lead to compile time conflicts with class member operator>>. You could specialize basic_istream for type uint32_t. But for specialization you should rewrite all fuctiono...
1,155,142
1,155,148
Why do I get an error in "forming reference to reference type" map?
What is the alternative if I need to use a reference, and the data I am passing I cannot change the type of, hence I cannot really store a pointer to it? Code: #include <map> #include<iostream> #include<string> using namespace std; int main() { string test; pair<string,...
You cannot store references. References are just aliases to another variable. The map needs a copy of the string to store: map<pair<string, string>, string> m; The reason you are getting that particular error is because somewhere in map, it's going to do an operation on the mapped_type which in your case is string&. O...
1,155,340
1,155,737
Migrating from Visual C++ 6 to Visual C++ 2008 express
I'm tring to migrate my code from VCpp 6 to VCpp 2008 express but when I build the solution I receive this error message: icl: warning: problem with Microsoft compilation of 'c:\Desenvolvimento\DFF\Base\\version.cpp' 1>C:\Arquivos de programas\Microsoft Visual Studio 9.0\VC\include\string.h(69): error: expected a ";...
The error was occuring because in the Visual C++ 6 I called Intel compiler from a .bat file to create a version number for my project. Now I'm using Microsoft compiler and I forgot to change the call.
1,155,539
1,156,742
How do I generate a Poisson Process?
Original Question: I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter λ how do I generate N(t)? How would I do this in C++? Clarification: I originally wanted to generate the process using a Poisson distribution. But, I was confused about w...
Here's sample code for generating Poisson samples using C++ TR1. If you want a Poisson process, times between arrivals are exponentially distributed, and exponential values can be generated trivially with the inverse CDF method: -k*log(u) where u is a uniform random variable and k is the mean of the exponential.
1,155,553
1,197,198
Alternatives to LogonUser for network impersonation (C++)
Are there any alternatives to LogonUser and for impersonating given account in order to access network resources? I'm looking for the method of impersonation which would let me connect to machine in foreign domains (or, workgroup machines for the same matter). For initial data I have: machine name, username (or domain...
If you're wanting to "access network resources" outside of your forest, do that with WNetAddConnection2/3 as you mentioned, or use the standard RPC APIs with RPC_ C__ AUTHN__ GSS__ NEGOTIATE and and explicit credentials structure. Normally, "impersonation" is something that happens on the server side. The server side w...
1,155,661
1,155,673
Anything like the c# params in c++?
That is the question. Background: C# Params In C#, you can declare the last parameter in a method / function as 'params', which must be a single-dimension array, e.g.: public void SomeMethod(int fixedParam, params string[] variableParams) { if (variableParams != null) { foreach(var item in variableParams)...
For unmanaged C++ with the same convenient syntax, no. But there is support for variable argument lists to functions in C++. Basically you declare a function with the last parameter being an ellipsis (...), and within the body of the function use the va_start()/va_arg() calls to parse out the supplied parameter list. T...
1,155,753
1,155,776
How are objects passed to functions C++, by value or by reference?
Coming from C#, where class instances are passed by reference (that is, a copy of the reference is passed when you call a function, instead of a copy of the value), I'd like to know how this works in C++. In the following case, _poly = poly, is it copying the value of poly to _poly, or what? #include <vector> using na...
poly's values will be copied into _poly -- but you will have made an extra copy in the process. A better way to do it is to pass by const reference: void polynomial::Set(const vector<int>& poly) { _poly = poly; } EDIT I mentioned in comments about copy-and-swap. Another way to implement what ...
1,155,989
1,160,099
How to add submenu to a CMenu in MFC?
I have an MFC app that uses CMenu for the main menu bar. I haven't been able to create submenus successfully. I can have the first level of File, Edit, View, etc and their sub menus, but I can't create a submenu off of one of those menus. For example, I would like to be able to go File->Recent Items->list of items in s...
Use your resource editor to add a submenu containing one placeholder item. You can then programatically grab a reference to this submenu, add items to it and delete the placeholder item: CMenu *subMenu = mainMenu.GetSubMenu( menuPosition ); if( subMenu ) { for( unsigned i = 0; i < stringArray.size(); i++ ) { ...
1,156,003
1,156,297
c++ namespace collision with gtest and boost
If I include both gtest/gtest.h and boost/math/distributions/poisson.hpp I get /opt/local/include/boost/tr1/tuple.hpp:63: error: ‘tuple’ is already declared in this scope /opt/local/include/boost/tr1/tuple.hpp:67: error: ‘make_tuple’ is already declared in this scope /opt/local/include/boost/tr1/tuple.hpp:68: error: ‘t...
Try building with BOOST_HAS_TR1_TUPLE defined. It looks like both boost and your std libraries are defining std::tr1::tuple and I can't see how to disable the std version. Looking at the boost header though it appears that BOOST_HAS_TR1_TUPLE needs to be defined to tell boost that std::tr1::tuple is already defined. I ...
1,156,020
1,156,047
Must every test-case undo their operation at the end?
The question may be a little vague but here's an example of what I want to know (pseudocode): //start test-case for CreateObject function { // initialization of parameters MyObject *obj = CreateObject(); // test results } //end test-case for CreateObject function Is it necessary in this case to also deallocate the mem...
In this case, you should deallocate the memory your test case has allocated. That way, you can use a tool that lets you run your tests and confirms that no memory was leaked. Letting your test code leak memory means that this would fail, and you wouldn't be able to tell for certain that the leak was in the test and not...
1,156,267
1,156,285
Where is <inttypes.h> in Visual Studio 2005?
I'd like to use the C99 header file inttypes.h in a Visual Studio project (I'd like to printf 64 bit numbers). However, this file does not seem to exist in my install. Is this just not part of VS2005? Are there any alternatives?
It's at google. VS doesn't come with <inttypes.h>
1,156,489
1,156,518
Way of overloading operator without changing original values?
I'm wondering if you can overload an operator and use it without changing the object's original values. Edited code example: class Rational{ public: Rational(double n, double d):numerator_(n), denominator_(d){}; Rational(){}; // default constructor double numerator() const { return numerator_; } // accessor ...
What you're looking for are the "binary" addition and subtraction operators: const Rational operator+(const Rational& A, const Rational& B) { Rational result; ... return result; } update (in response to new code and comments): You are getting that error because your accessor functions are not declared ...
1,156,652
1,156,766
Encapsulate Windows message loop into a DLL
I would like to have a DLL with window creation and management code in a way that the developer could just add a named main.h header and load the DLL to be able to instance a window. #include "dllheader.h" void user_main(); main = user_main; // attach user main to the dll callback int user_main() { Window *w = ...
Every Win32 application must have an entry point (usally WinMain). So you can't put the entry point in the DLL, because it's not really part of the EXE. However the entry point can be in a statically linked library. When the static library gets linked, the entry point becomes part of the EXE. But my suggestion is to av...
1,156,746
1,156,757
Integrate Adobe AIR With C++
I'm learning C++ and before this i was reading some tutorials in the internet of the Adobe AIR development, but if Adobe AIR is so much easy to learn and C++ is a very flexible and good language it's possible to integrate those two languages in a same project. Thanks!
It's in the works. For now, you use either JavaScript or ActionScript. An alternative to AIR is Titanium. Its language choices are JavaScript, Ruby, and Python.
1,156,756
1,157,063
Joining keys/values from C++ STL associative containers
I have a join function that operates on STL strings. I want to be able to apply it to to a container like this: getFoos(const std::multimap<std::string, std::string>& map) { return join_values(",", map.equal_range("foo")); In other words, find all matching keys in the collection and concatenate the values into a ...
The STL algorithms typically work with iterators, not containers, so I would suggest something like the following. template <typename T, typename Iterator> T join( const T sep, Iterator b, Iterator e) { T t; while (b != e) t = t + *b++ + sep; return t; } Then, you need an iterator tha...
1,156,783
1,156,795
How to increase the gcc executable stack size?
I have large Boost/Spirit metaprogram that is blowing gcc's stack when I try to compile it. How can I increase gcc's stack size, so I can compile this program? Note: There's no infinite recursion going on, but there is enough incidental recursion to exhaust gcc's stack.
On Linux, you can expand the stack size in /etc/security/limits.conf. You can check your current stack size by using $ ulimit -s 8192 Then expand the stack to be double than that: youruser soft stack 16384 And then relog. This will increase stack size for all executable you're running, not just GCC's.
1,157,107
1,157,131
Enter File Name When Executing Program In C++
I'm learning C++, then i was searching for some codes for learn something in the area that i love: File I/O, but i want to know how i can tweak my code for the user type the file that he wants to see, like in wget, but with my program like this: C:\> FileSize test.txt The code of my program is here: // obtaining file ...
In the example below argv contains command line arguments as null terminated string array and argc contains an integer telling you how many arguments where passed. #include <iostream> #include <fstream> using namespace std; int main ( int argc, char** argv ) { long begin,end; if( argc < 2 ) { cout << "No fi...
1,157,235
1,157,244
Is this a good practice? "/*/something/*/something//*/"
/*/ comment here do some thing. /*/ do some thing. //*/ Why people write code like that? Is this a good practice?
It's usually only used when testing something out for the moment. That is, you should never commit code like that to version control, because it can be confusing. For example, if you are testing two different computation methods, you can use this to switch between them. Personally I have rarely done this, if at all. F...
1,157,357
1,157,435
Qt: Add UI Elements using Qt Script
Is it possible to add new GUI elements into a Qt program using QtScript? For instance assuming the variable "layout" is a vertical layout would this be acceptable? var label = new QLabel("Text"); layout.addWidget(label);
Qt doesn't ship with QtScript bindings; which bindings are you using? If you're using the bindings generator on Qt Labs, yes, this code would work fine, assuming you arranged for the `layout' variable to be imported into your script engine.
1,157,591
1,157,622
What type of exception should I throw?
After going through some links on exception handling (1, 2, and 3), I know that C++ programs can throw pretty much anything as exceptions (int, char*, string, exception class). I know that std::exception is the base class for standard exceptions thrown by the program. However, I'm trying to design a try...catch block a...
You would derive your own class from std::exception, so that there is some way of uniformly handling exceptions. If this seems like overkill, you can throw std::logic_error or one of the other standard exception types intended for applications to use. You could also use these as base classes for your own more specific...
1,157,689
1,163,172
Finding the nearest used index before a specified index in an array (Fast)
This question is related to Array of pairs of 3 bit elements This array has 52 pairs (about 40 bytes), and I want to find the first pair before the specified one that has it's values different from 0 (used pair). The obvious solution would be to check each pair < than this one (scan from right to left), but this seems ...
The best solution I found was: 1. make the items 1 byte (not 6 bits than before) - thanks Skizz 2. use a bitmap to see which item is the nearest on the left. This was much faster than going back with the technique described by djna. The speed improvements are impressive: in one test case, from 13s it's now 6.5s in an...
1,158,084
1,158,306
temporary object, function parameters and implicit cast
In the following scenario: struct Foo { // ... operator Bar() {... } // implicit cast to Bar } Foo GetFoo() { ... } void CallMeBar(Bar x) { ... } // ... CallMeBar( GetFoo() ); [edit] fixed the cast operator, d'oh[/edit] GetFoo returns a temporary object of Type Foo. Does this object survive until after CallMe...
Regardless of the cast, the temporary object(s) will "survive" the call to CallMe() function because of the C++ standard: 12.2.3 [...] Temporary objects are destroyed as the last step in evaluating the fullexpression (1.9) that (lexically) contains the point where they were created. [...] 1.9.12 A fullexpression is an ...
1,158,373
1,158,438
Getting the number of logged on users in Windows
Let's say I have 3 logged on users. I have a test application which I use to enumerate the WTS sessions on the local computer, using WTSEnumerateSessions. After that, I display the information contained in each of the returned WTS_SESSION_INFO structure. On Windows XP, there are 3 structures displayed: Session 0, 1, an...
http://www.codeproject.com/KB/system/logonsessions.aspx Same information available on Getting user name/password of the logged in user in Windows Try going through this articles:- ( this is for using ASP ...) http://support.microsoft.com/default...b;EN-US;308157 http://www.c-sharpcorner.com/Code/20...cationWithAD.asp
1,158,374
1,194,024
Portable Compare And Swap (atomic operations) C/C++ library?
Is there any small library, that wrapps various processors' CAS-like operations into macros or functions, that are portable across multiple compilers? PS. The atomic.hpp library is inside boost::interprocess::detail namespace. The author refuses to make it a public, well maintained library. Lets reopen the question, an...
Intel Threading Building Blocks has a nice portable atomic<T> template which does what you want. But whether it is a small library or not can of course be debated..
1,158,390
1,158,489
Binding to a member variable
I am confused as to what boost::bind does when we bind to member variables. With binding to member function, we essentially create a function object, and then call it passing to it the arguments that are provided or delayed and substituted via placeholders. But what does this expression do behind the scenes: boost::bin...
Behind the scenes it is using a member pointer and applying it to the passed in argument. It is quite complex in the context of binds, so here is a simple example of pointer to member usage: int main() { std::pair< int, int > p1 = make_pair( 1, 2 ); std::pair< int, int > p2 = make_pair( 2, 4 ); int std::pair<i...
1,158,410
1,158,415
How to handle incorrect values in a constructor?
Please note that this is asking a question about constructors, not about classes which handle time. Suppose I have a class like this: class Time { protected: unsigned int m_hour; unsigned int m_minute; unsigned int m_second; public: Time(unsigned int hour, unsigned int minute, unsigned int second); }; ...
The typical solution is to throw an exception. The logic behind that is the following: the constructor is a method that transforms a chunk of memory into a valid object. Either it succeeds (finishes normally) and you have a valid object or you need some non-ignorable indicator of a problem. Exceptions are the only way ...
1,158,519
1,158,542
Crash when using C# Assembly from Managed C++ DLL
On a Windows XP system, I'm writing a Mangaged C++ library which calls code in a C# Assembly. Unfortunately, as soon as I start referencing a symbol in the C# Assembly, running the Managed C++ library fails with this error (I copied this from the XP crash dialog): EventType : clr20r3 P1 : treeviewdemo.exe P2 : 0.0.0.0 ...
Are all the dependencies of MyCSharpAssembly.dll available on the same path? If you are not sure, try loading the C-Sharp Assembly in ILDasm Tool to find out what are its dependencies. As a sanity check, also check that whether this C-Sharp DLL can be loaded from another C-Sharp executable or not.
1,158,705
1,158,765
MSVCP90.dll not found?
in my project if compile project in release, it asks me MSVCP90.dll. if it is debug, it does not... have you ever met such a situation? and do you know why this .dll is desired? or what configuration makes it to be desired? thanks for any advice..
i realized that i already installed Microsoft Visual C++ 2008 Redistributable Package so i just repaired but it did not solved the problem. then i looked for the configuration and saw that "Generate Manifest" is "No" in Release when it was "Yes" in Debug. so i changed and tried again then it worked. i did not know that...
1,159,042
1,159,086
Is there any user-mode multi-threading library/framework for C++ under Linux?
I am looking for user-mode multi-threading library/framework for C++ under Linux. I am familiar with boost::thread and ACE_Thread_Manager but AFAIK both of them eventually use OS native thread's support. Suggestions will be highly appreciated.
Is MTasker the kind of thing you're looking for? It's also a cooperative multi-tasking library. You might also want to consider just whipping up some state machines. Also check out State Threads and MIT Pthreads. This tool will assist in the generation of hierarchical state machines, which could be used for this purp...
1,159,100
1,159,139
Put A String In A ifstream Method
I'm learning C++ and i'm getting some troubles when i'm trying to use a String in a ifstream method, like this: string filename; cout << "Enter the name of the file: "; cin >> filename; ifstream file ( filename ); Here is the full code: // obtaining file size #include <iostream> #include <fstream> using namespace s...
You should pass char* to ifstream constructor, use c_str() function. // includes !!! #include <fstream> #include <iostream> #include <string> using namespace std; int main() { string filename; cout << "Enter the name of the file: "; cin >> filename; ifstream file ( filename.c_str() ); // c_str !!! }
1,159,429
1,202,533
class_id in boost::archive::xml_oarchive
Is it possible for XML serialization to use more human friendly class_id as GUID, described using BOOST_CLASS_EXPORT_GUID ??? Consider serializing class: SomeClass* b=new SomeClass("c"); { boost::archive::xml_oarchive oa(cout); oa.register_type<SomeClass>(); oa << boost::serialization::make_nvp("b",b); } O...
Yes, the solution is to serialize your class in a name-value-pair. See this item at boost documentation. If you want two diferent behaviours, you will have to implement them. Try with template specialization: template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & degrees; ar & m...
1,159,753
1,159,972
Constructor of class in template
I have a object cache class like this: #include "boost/thread/mutex.hpp" #include "boost/unordered_map.hpp" template <typename type1, typename type2> class objectCache { public: objectCache() { IDCounter = 0; } ~objectCache() { for ( it=free_objects.begin() ; it != free_objects.end(...
Rather than passing an explicit value, pass in an object that creates your instance for you: template <typename type1> struct DefaultInstanceCreator { type1 * operator ()() const { return new type1; } }; template < typename type1 , typename InstanceCreator = DefaultInstanceCreator<type1> > class objec...
1,159,992
1,161,346
Decompression and extraction of files from streaming archive on the fly
I'm writing a browser plugin, similiar to Flash and Java in that it starts downloading a file (.jar or .swf) as soon as it gets displayed. Java waits (I believe) until the entire jar files is loaded, but Flash does not. I want the same ability, but with a compressed archive file. I would like to access files in the arc...
There are 2 issues here How to write the code. What format to use. On the file format, You can't use the .ZIP format because .ZIP puts the table of contents at the end of the file. That means you'd have to download the entire file before you can know what's in it. Zip has headers you can scan for but those headers ar...
1,161,142
1,193,644
Not receiving callbacks from the Java Access Bridge
I'm trying to use the Java Access Bridge to get information about Swing components from inside a C++ app. However, none of the callbacks I register ever get called. I tried enuming the windows an then calling IsJavaWindow() on each handle, but it always returns false. Any ideas on why it apparently is not working? I...
I have been fighting this one as well, and have just found a solution that actually makes sense. I ended up having to build a debug version of the WindowsAccessBridge.dll and used the debugger to step into it to watch what was happening. The call to 'initializeAccessBridge' REQUIRES you to have an active windows mess...
1,161,182
1,161,330
C++ w/ static template methods
Template methods as in NOT C++ templates. So, say that you would like to do some searching with different algorithms - Linear and Binary for instance. And you would also like to run those searches through some common routines so that you could, for instance, automatically record the time that a given search took and ...
I don't see why you'd need the template method pattern. Why not just define those algorithms as functors that can be passed to your benchmarking function? struct BinarySearch { // functor implementing a specific search algorithm template <typename iter_type> void operator()(iter_type first, iter_type last){ ....} }...
1,161,295
1,161,312
Reading .docx in C++
I'm trying to create a program that reads a .docx file and posts it content to a blog/forum for personal use. I finally have figured out how to use libcurl to do (what I figured) was the harder part of the program. Now I just have to read the .docx file, but have come under a snag. I can't seem to find any documenta...
The easiest way is to use Word to do this. It has limitations on licensing. The SO question Creating, opening and printing a word file from C++ has some good references. Edit: According to these questions/answers can unzip the Open XML file and process the XML file directly: How can I read a Word 2007 .docx file? If ...
1,161,582
1,161,621
Makefile, source in multiple directories, dependency problem
I am experimenting with makefile...mainly when sources are in many directories I have following situation... project/src/ contains directory A, B, Main Directory A contains A.h and A.cpp; B contains B.cpp and B.h; and Test contains test.cpp A.cpp includes A.h; B.cpp includes B.h and Main.cpp includes A.h, B.h project/l...
You really need to add a rule which knows how to make libA and libB, then add the dependency from test onto that rule. The rule can either call make in that directory (recursive make), or explicitly encode the rules for building the libs in your makefile. The first one is more traditional and is pretty simple to unders...
1,161,887
1,161,908
What happens if I cast a double to an int, but the value of the double is out of range?
What happens if I cast a double to an int, but the value of the double is out of range? Lets say I do something like this? double d = double(INT_MIN) - 10000.0; int a = (int)d; What is the value of a? Is it undefined?
Precisely. Quoting from the Standard, 4.9, "The behavior is undefined if the truncated value cannot be represented in the destination type."
1,162,050
1,163,681
CreateRemoteThread, LoadLibrary, and PostThreadMessage. What's the proper IPC method?
Alright, I'm injecting some code into another process using the CreateRemoteThread/LoadLibrary "trick". I end up with a thread id, and a process with a DLL of my choice spinning up. At least in theory, the DLL does nothing at the moment so verifying this is a little tricky. For the time being I'm willing to accept it...
Step zero; the injected DLL should have an entry point, lets call it Init() that takes a LPCWSTR as its single parameter and returns an int; i.e. the same signature as LoadLibrary() and therefore equally valid as a thread start function address... Step one; inject using load library and a remote thread. Do nothing clev...
1,162,059
1,211,079
How to make custon data source in QlikView?
I have just started to develop in QlikView so I'm completely a newbie. The problem that I have is that I need to create a c++ dll that can be used as a custom data source for QlikView, I already created the dll and QlikView can see it, but I don't know how should I do to make my data available to QlikView. The data tha...
Just if someone is interested, I posted the same question in the QlikView Forum and the answer that I got was "Get the version 9 SDK. It includes doc and a sample for a Custom Data Source. The SDK is available on a QV Server installation. If not already installed, I believe you can download the QVS9 and just install ...
1,162,068
1,162,076
Redirect both cout and stdout to a string in C++ for Unit Testing
I'm working on getting some legacy code under unit tests and sometimes the only way to sense an existing program behavior is from the console output. I see lots of examples online for how to redirect stdout to another file in C++, but is there a way I can redirect it to an in-memory stream so my tests don't have to rel...
std::stringstream may be what you're looking for. UPDATE Alright, this is a bit of hack, but maybe you could do this to grab the printf output: char huge_string_buf[MASSIVE_SIZE]; freopen("NUL", "a", stdout); setbuf(stdout, huge_string_buffer); Note you should use "/dev/null" for linux instead of "NUL". That will r...
1,162,139
1,162,169
Copying C++ API header files to a common directory
I have a Visual Studio 2008 solution comprised of several projects. Only some header files in each project represents API to the library built from the project. Is there a way in Visual Studio to copy the files to a common directory prior compilation? (I want to do it in order prevent including unintentionally header f...
Yes, on the project menu, select properties->configuration properties->build events->pre-build event. In the command line section you can enter a copy command with your source and destination paths. You may find the $solutiondir macro useful when enterting your paths.
1,162,262
1,162,291
How can I simulate a C++ union in C#?
I have a small question about structures with the LayoutKind.Explicit attribute set. I declared the struct as you can see, with a fieldTotal with 64 bits, being fieldFirst the first 32 bytes and fieldSecond the last 32 bytes. After setting both fieldfirst and fieldSecond to Int32.MaxValue, I'd expect fieldTotal to be I...
The reason is that FieldOffsetAttribute takes a number of bytes as parameter -- not number of bits. This works as expected: [StructLayout(LayoutKind.Explicit)] struct STRUCT { [FieldOffset(0)] public Int64 fieldTotal; [FieldOffset(0)] public Int32 fieldFirst; [FieldOffset(4)] public Int32 fiel...
1,162,279
1,164,739
Streaming over a TCP/IP connection
I find myself constantly running into a situation where I have a set of messages that I need to send over a TCP/IP connection. I have never found a good solution for the design of the message class. I would like to have a message base class where all messages derive from it. Since each message will have different field...
"The problem with that solution is that with so many calls to send data, the context switches will slam the processor. Also, the streaming operator ends up the the socket class and not in the message class where I would prefer it lived." The solution to the second problem is to define operator<< as a non-member functio...
1,162,401
1,162,910
Is it possible to access values of non-type template parameters in specialized template class?
Is it possible to access values of non-type template parameters in specialized template class? If I have template class with specialization: template <int major, int minor> struct A { void f() { cout << major << endl; } } template <> struct A<4,0> { void f() { cout << ??? << endl; } } I know...
This kind of problem can be solved by having a separate set of "Traits" structs. // A default Traits class has no information template<class T> struct Traits { }; // A convenient way to get the Traits of the type of a given value without // having to explicitly write out the type template<typename T> Traits<T> GetTrai...
1,162,619
1,162,786
Fastest quote-escaping implementation?
I'm working on some code that is normalizing a lot of data. At the end of processing, a number of key="value" pairs is written out to a file. The "value" part could be anything, so at the point of output the values must have any embedded quotes escaped as \". Right now, I'm using the following: outstream << boost::reg...
If speed is a concern you should use a hand-written function to do this. Notice the use of reserve() to try to keep memory (re)allocation to a minimum. string escape_quotes(const string &before) { string after; after.reserve(before.length() + 4); for (string::size_type i = 0; i < before.length(); ++i) { ...
1,162,646
1,162,806
Microsoft Visual C++ 2003, 2005-- Are They .Net or Unmanaged?
It's kind of confusing when it comes to Microsoft Visual C++. How to tell whether a Microsoft Visual C++ project is a .Net project, or a native C++ project?
usually if the switch /clr:xxx is present it is managed code I say usually since if you apply /clr:xxx on unmanaged C++ code you get a warning
1,162,698
1,162,723
How I Can Print The IP Of The Host
I'm learning C++ and i want to know how i can print the IP adress of the host machine, but remember that my program is a command line aplication(cmd), but i don't want the code, but some links here i can learn this, not copy and paste. Thanks!
Check this out: Socket Programming. Winsock looks like a good choice.
1,162,810
1,195,406
Compiling MySQL custom engine in Visual Studio 2008
I have compilation errors while compiling MySQL sample of storage engine from MySQL 5.1.36 sources. Looks to me that I set all paths to include subdirectories but that seems not enough. Here are the errors: 1>c:\users\roman\desktop\mysql-5.1.36\sql\field.h(1455) : error C2065: 'FRM_VER' : undeclared identifier 1...
I had to include mysql_version.h.in library that contain all appropriate variables like FRM_VER, etc. That resolved the errors metioned above.
1,162,933
1,162,945
Create header file from COM TLB
Given a managed COM object and an associated tlb file, I would like to access it from some unmanaged C++ code WITHOUT using the TLB/import command. But use a header file. Is there a way to extract a header file from a TLB? Thanks
I found it (on a whim). The OLE/COM Viewer allows you to save a TLB file as a header, C, or IDL file! Very cool! Thanks!
1,163,236
1,163,315
Signal/Slot vs. direct function calls
So I have starting to learn Qt 4.5 and found the Signal/Slot mechanism to be of help. However, now I find myself to be considering two types of architecture. This is the one I would use class IDataBlock { public: virtual void updateBlock(std::string& someData) = 0; } class Updater { private: void update...
Emmitting a signal costs few switches and some additional function calls (depending on what and how is connected), but overhead should be minimal. Provider of a signal has no control over who its clients are and even if they all actually got the signal by the time emit returns. This is very convenient and allows comple...
1,163,242
1,163,255
"class std::map used without template paramaters" error
I'd have to say I'm no expert on using the STL. Here's my problem, I have a class Called LdapClientManager which maintains a number of LDAP clients that are managed by ID. The container holding the LdapClients is declared as a member variable i.e. typedef std::map<int, LdapClient *> LdapClientMap; LdapClientMap _ldapC...
Replace std::map::end with _ldapClientMap.end(). Also, new never returns 0, it throws an exception if the allocation fails. Note that the program can be made much shorter. LdapClient * LdapClientManager::getLdapClient(unsigned int templateID) { LdapClient *& value = _ldapClientMap[templateID]; if (value == 0) ...
1,163,503
1,163,519
What is difference between RegAsm.exe and regsvr32? How to generate a tlb file using regsvr32?
Can any body tell me what is the difference between regsvr32 and RegAsm? My Dll is in C#, so how can I import the classes to c++?
regsvr32 will load the library and try to call the DllRegisterServer() from that library. It doesn't care what DllRegisterServer() actually does - it just calls that function and checks the returned value. You use it to register COM servers in unmanaged DLLs. It can't generate a .tlb file. regasm will register a COM-ex...