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,520,734 | 1,520,824 | What libraries are available for parsing c++ to extract type information | I'm looking for a way to parse c++ code to retrieve some basic information about classes. I don't actually need much information from the code itself, but I do need it to handle things like macros and templates. In short, I want to extract the "structure" of the code, what you would show in a UML diagram.
For each clas... | Sounds like a job for gcc-xml in combination with the c++ xml-library or xml-friendly scripting language of your choice.
|
1,520,983 | 1,521,129 | Generating and saving code from Macro | I am analyzing a legacy code which heavily using macro, I am lost in understanding how macro are expanding in code.
Could any one suggest me some tool or technique so that I can study actual code generated from macro expansion.
Platform : Windows XP
Language : C++
Compiler : VC6
| With visual studio you can use the Generate Preprocessed File option.
In the properties for your project select
C/C++/Preprocessor/
In that tab there is an option to:
generate a preprocessed file.
Select Yes, with numbers.
|
1,520,986 | 1,526,167 | Open file in TagLib with Unicode chars in filename | I am quite new to the C++ 'area' so I hope this will not be just another silly 'C++ strings' question.
Here is my problem. I want to integrate TagLib (1.5, 1.6 as soon as I manage to build it for Windows) into an existing Windows MFC VS2005 project. I need it to read audio files metadata (not write).
The problem is th... | I missed something essential when I first read your post, so here is another, new and improved answer:
The error comes from the linker, not the compiler. It thus seems that TagLib::FileName does have a ctor taking wchar_t const*, but the problem is that you don't link with the library implementing it, or link with a ve... |
1,521,062 | 1,521,171 | Can I do a multidimensional char array in c++? | First off, this is a "homework" question so vector libraries and string libraries are off limits. I'm trying to get to the basics of c++.
My intention with this code is to make and use an array of string arrays. A list of words in other words.
When I run this code I get a bunch of nonsense.
If there is a better way to ... | I don't exactly understand what you are looking for. Following code will help you to read and print a list of 50 words. Hope this would help you.
const int cart_length = 50;
const int word_length = 50;
int main()
{
char cart_of_names[cart_length][word_length];
float cart_of_costs[cart_length];
for(int i... |
1,521,080 | 1,521,141 | How to convert Text to Wave using SAPI with multithreading? | I am trying to convert text to wave file using following function. It works fine if called from main UI thread. But it fails when calling from another thread. How to call it from a multi-threaded function?
void Pan_Channel::TextToPlaybackFile( CString Text, CString FileName )
{
// Result variable
HRESULT Result = S_O... | Have you CoInitialized the other thread? COM needs to be initialized on each thread using it. Also .. do you use a COM object created in one thread in another thread? Because you need to marshall the interface between threads if you do that ...
|
1,521,281 | 1,521,305 | What are the STL string limits? | What are the string limits for the Standard Template Library in C++?
| #include <iostream>
#include <string>
int main() {
std::cout << std::string().max_size() << std::endl;
return 0;
}
|
1,521,518 | 1,521,642 | Multithreading in wxWidgets GUI apps? | I'm having problem (basically, I'm confused.) while trying to create a worker thread for my wxWidgets GUI application that WILL MODIFY one of the GUI property itself. (In this case, wxTextCtrl::AppendText).
So far, I have 2 source files and 2 header files for the wx program itself (excluding my own libs, MySQL lib, etc... | The easiest is to create an event type id, and use a wxCommandEvent using the type id, set its string member ("evt.SetText"), and send the event to one of your windows (using AddPendingEvent). In the handler of that event, you can then call AppendText on your control using the text you sent (evt.GetText), because you a... |
1,521,607 | 1,521,682 | Check double variable if it contains an integer, and not floating point | What I mean is the following:
double d1 =555;
double d2=55.343
I want to be able to tell that d1 is an integer while d2 is not. Is there an easy way to do it in c/c++?
| Use std::modf:
double intpart;
modf(value, &intpart) == 0.0
Don't convert to int! The number 1.0e+300 is an integer too you know.
Edit: As Pete Kirkham points out, passing 0 as the second argument is not guaranteed by the standard to work, requiring the use of a dummy variable and, unfortunately, making the code a lot... |
1,521,924 | 1,521,941 | C++ program halts after dynamic memory allocation | I'm having problem with a copying method in a simple C++ program.
Everytime I call copy:
Sudoku::SudokuNode** Sudoku::copy(SudokuNode** sudokuBoard)
{
SudokuNode** tempSudokuBoard = new SudokuNode*[9];
for(int i = 0; i<9; i++)
{
tempSudokuBoard[i] = new SudokuNode[9];
for(int j = 0; j<9; j++)
{
tempS... | for(vector<int>::iterator iter = sudokuBoard[i][j].possibleIntegers.begin(); iter!= sudokuBoard[i][j].possibleIntegers.end();)
You don't seem to be advancing the iterator in that loop, so it will never end. Add ++iter to the counting expression (after the last ; in the for loop).
As to why your debugger can't find... |
1,522,107 | 1,522,123 | How can I communicate between two C++ MFC plugins? | I have a plugin for a c++ MFC app. I'm working with the developer of another plugin for the same app, that's trying to get notifications of events in my code. Both plugins are in the form of c++ dlls.
How can I pass messages from my plugin to his plugin? The solution needs to be robust to mismatched versions of our ... | Take a look at this article here, it shows the available IPC mechanisms in windows. I might try COM, Mailslots, Pipes or Shared Memory (file mapping) in your case, in addition to windows messages which you already mentioned.
|
1,522,141 | 1,522,156 | Is there any advantage in using a reference argument in this function? | I have defined the following class:
class Action
{
public:
Action(){ _bAllDone = false; }
void AddMove( Move & m );
private:
std::deque<Move> _todo;
bool _bAllDone;
};
The member AddMove is defined as follows:
void Action::AddMove( Move & m )
{
_todo.push_back( m );
}
I noted t... | The deque class in STL is supposed to maintain a copy of the element you pass to its push_back method. That is where one copy constructor comes from.
If you get rid of the reference in addMove(), you will first get a copy of the parameter (and thus one invocation of the copy constructor), and then when you push back, y... |
1,522,149 | 1,522,175 | c++ vectors - Using find(begin, end, term) | Ok, i'm doing this and it works fine.
end = std::find(arToken.begin() + nStart, arToken.end(), ".");
I want to extend the . to include ! and ? so it finds periods(.), exclamation mark(!), and question mark(?).
Should i use regex in the term?
TIA
| you should use std::find_first_of:
std::string m(".!?");
end = std::find_first_of(arToken.begin() + nStart, arToken.end(), m.begin(),m.end());
|
1,522,373 | 1,522,389 | Header class file to be used by others | I would like to know if there is a way to put only protected and public stuff on the header file .h, and all private stuff in the compile unit .cpp
I need this because the library is going to be used by others, and I wouldn't like to have to copy and edit all .h files to remove private declarations and implementations.... | The proper way to deal with this is to implement the pimpl idiom: Create a class or struct for all private data and put a pointer to such an object in the header file, together with a forward declaration. Now nothing of the private data and methods is visible from the header file.
|
1,522,555 | 1,522,583 | c++ winsock2, how to tell when a connection closes | I have a c++ program using winsock2. I would like to know how to tell when someone's connection to my program closes.
| Use select to wait for reading on the socket; when the socket is closed winsock should report it as readable. Receiving from the socket will then give you 0 bytes, telling you that the socket was closed.
|
1,522,728 | 1,522,766 | Is it possible to force a string to be a specific size when defining a struct? | I am marshalling data between a C# and C++ application. In the C# application, I force the size of a string to be some size (say, 256 bytes). I would like to read in that exact same amount in C++ (I will be recreating the structs with reinterpret_cast) so that the data will remain formatted as it was in the C# applic... | In general you're taking the wrong approach here. Mixing non-data only C++ types and PInvoke will lead you to a lot of pain. Types like std::string should not be used in this scenario because the marshaller cannot correctly create them at runtime.
Instead you need to use more primitive types. In this particular scen... |
1,522,789 | 1,522,802 | Can I make a bitwise copy of a C++ object? | Can C++ objects be copied using bitwise copy? I mean using memcopy_s? Is there a scenario in which that can go wrong?
| If they're Plain Old Data (POD) types, then this should work. Any class that has instances of other classes inside it will potentially fail, since you're copying them without invoking their copy constructors. The most likely way it will fail is one of their destructors will free some memory, but you've duplicated poi... |
1,522,828 | 1,522,836 | traversing a singly linked list in C++ | I was wondering if it is possible to traverse a linked list like this:
currentNode = randomNode;//where randomNode may or may not = firstNode
prevNode = firstNode;
while(prevNode != currentNode && prevNode->link != currentNode)
{
prevNode = prevNode->link;
}
Is it possible to do this in C++ when I am trying to fi... | You might want to make sure that prevNode->link is not a null reference either, in case currentNode is not actually linked.
|
1,522,853 | 1,522,878 | Creating your own HRESULT? | I already have a project that uses a lot of COM, and HRESULTS. Anyways I was wondering if it's possible to define your own HRESULT, AND be able to use the FormatMessage() for our own HRESULT?
I dug around and can't find anything. Any ideas?
EDIT
Basically I want to define a set of my own HRESULTs instead of just return... | Yes of course. Typically you create a .mc file and include that in your project. Instruct the mc compiler to build it - this creates a header file and a .rc file. The HRESULTS are defined in the header file. You include the .rc file in your project as normal for the resource compiler to compile - this puts the message ... |
1,522,912 | 1,523,011 | Reference in lhs and rhs difference in C++ | I am learning C++ and I found that when a reference is on the right hand side, there can be two cases. Suppose I have a method:
int& GetMe(int& i) { return i; }
And I have:
(1) int j; GetMe(j) = GetMe(i);
and
(2) int& k = GetMe(i);
The consequences of (1) and (2) are different. In (1), the semantic is to copy the valu... | What you are missing here is that type of variable is different and it is all that matters. In first example you have int j and in second - int &k.
References in functions prototypes exists in different grounds, they looks the same, underneath they are pretty much the same but they used differently because they exists ... |
1,522,994 | 1,523,082 | Store an int in a char array? | I want to store a 4-byte int in a char array... such that the first 4 locations of the char array are the 4 bytes of the int.
Then, I want to pull the int back out of the array...
Also, bonus points if someone can give me code for doing this in a loop... IE writing like 8 ints into a 32 byte array.
int har = 0x01010101... | Not the most optimal way, but is endian safe.
int har = 0x01010101;
char a[4];
a[0] = har & 0xff;
a[1] = (har>>8) & 0xff;
a[2] = (har>>16) & 0xff;
a[3] = (har>>24) & 0xff;
|
1,523,142 | 1,523,149 | Boost equivalent of memcpy? | Is there a boost equivalent for memcpy? Thanks!
EDIT: Sorry, I didn't realize memcpy was in the standard library :)
I thought it was an OS call :(
| Does there need to be one? What's wrong with memcpy? Although it comes from C, it's a perfectly valid C++ function. If you want something that's aware of C++ objects and their assignment operators, then use std::copy. You might also want to take a look at std::uninitialized_copy.
|
1,523,186 | 1,523,195 | What is the proper method of reading and parsing data files in C++? | What is an efficient, proper way of reading in a data file with mixed characters? For example, I have a data file that contains a mixture of data loaded from other files, 32-bit integers, characters and strings. Currently, I am using an fstream object, but it gets stopped once it hits an int32 or the end of a string.... | Have you ever considered that the file reading is working perfectly and it is printf(mymemory) that is stopping at the first null?
Have a look with the debugger and see if I am right.
Also, if you want to print someone else's buffer, use puts(mymemory) or printf("%s", mymemory). Don't accept someone else's input for th... |
1,523,386 | 1,860,001 | Sharing code between projects without svn:externals | In order to simplify the build process, I've been trying to reorganize my version control repository.
I am developing a simple client-server application. Following Rob Williams' advice, I have separated the client and the server into separate projects each with their own lifecycle. The problem though, is that client an... | Why don't you put your common code into a third repository. Then use a convention for naming your working copies, so that you can use relative include paths like ../shared/someheader.h
|
1,523,483 | 1,523,497 | Does GCC support long long int? | Does GCC support:
long long int
which would be a 64-bit integer?
Also, is long long int part of the standard?
| Yes GCC does support long long int, which is a part of C99 standard.
The standard does not mandate its size in bits, but required values of LLONG_MIN and LLONG_MAX in <limits.h> imply it's at least 64-bit (exact 64-bit wide integer types are int64_t/uint64_t from <stdint.h>).
LLONG_MIN must be at most -922337203685477... |
1,523,732 | 1,523,870 | Where hardcoded values are stored? | For an investigation i need to know where hard-coded values are stored.
Question : A function having hard-coded values inside it , and this function is called by many threads at same time , is there any chance that that hard-coded value will be corrupted.
For example : myFunc is called by many thread at same time .
... | Literal strings are stored in the .data section of your program image when they are compiled. The .data section is usually mapped into read only memory so it cannot be corrupted just like the .code section. You can view the .data section of a windows exe/dll by using dumpbin.exe that comes with visual studio.
There i... |
1,523,802 | 1,525,470 | How to place 90X90 icon | i am creating .cab file installer for windows mobile application,
problem is i need to keep the 90X90 .png image as icon for application.
as per the link
i tried to load the icon,step am following are
1) writing the icon path to registry
2) then loading the icon...
i followed the step mentioned above link,
but the prob... | The Windows Mobile shell caches the icon. On your first install on a clean device, your icon will be used. After that, the icon will remain in the cache until the device is reset, so if you want to change an icon with an already-installed app, you have to soft reset to force the shell to reload the cache.
Again, this... |
1,523,822 | 1,524,277 | Win32Api - Window Name Property | Is there any way to get a control's name through win32api? (c++)
I'm talking about the property that in C# is 'Name', like 'frmMain', or 'btnNext'.
Is there any way to retrieve this data through the win32API?
I've tried GetWindowInfo() and stuff but I think I'm not heading in the right direction..
thanks
edit: I'm ite... | I seriously doubt that this information is even in the executable code, I would think that from the c# compilers point of view these symbols get reduced to object pointers or window identifiers values (the IDC_ mentioned above).
Having been faced with this type of problem before I chose to create hidden static text con... |
1,523,888 | 1,523,893 | which namespace does toupper belong to | when I'm reading some c++ sample code for beginner , I'm puzzled at the usage of toupper in the following line :
std::transform(data.begin(), data.end(), data.begin(), ::toupper);
from the above line, I know that "transform" is from namespace std , but I don't know which namespace does toupper come from . maybe there ... | If you include
<cctype>
then toupper() is in namespace std. If you include
<ctype.h>
then toupper() is in the global namespace. (The one everything ends up in if not defined in a specific namespace. The one you refer to with a leading :: when you're in a specific namespace.)
The same rule applies to <cstring> vs. <st... |
1,523,916 | 1,523,976 | How to handle same socket in different threads? | I am trying to handle socket in different threads creating runtime failure. See following code.
void MySocket::Lock()
{
m_LockCount++;
if( m_LockCount )
{
CSocket::Create( 8080 );
}
}
void MySocket::Unlock()
{
m_LockCount--;
if( !m_LockCount )
{
CSocket::Close();
}
}
... | If, as you say, "a CSocket object should be used only in the context of a single thread," then there is no "mechanism to share CSocket among threads".
In other words, one of the threads needs to own the CSocket, and the others can't mess with it.
In such cases, the solution is to use an inter-thread messaging system. T... |
1,523,981 | 1,524,006 | API for Giving Notification when a file is added or deleted in a folder | is there any windows API or shell API which will give a notification on when a file is added or deleted in a folder
| These API's can help you. and you can find a nice tutorial here
FindFirstChangeNotification
FindCloseChangeNotification
FindNextChangeNotification
|
1,524,139 | 1,524,387 | ANSI C functions namespace in ISO C++ | Consider the following small program:
#include <cstdio>
int main() {
printf("%d\n", 1);
std::printf("%d\n", 2);
return 0;
}
What does C++ standard say about importing C library functions into global namespace by default? Can you point me to the relevant C++ standard section?
What is the reason ANSI C fun... | 7.4.1.2/4:
Except as noted in clauses 18 through 27, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in ISO/IEC 9899:1990 Programming Languages C (Clause 7), or ISO/IEC:1990 Programming Languages—C AMENDMENT 1: C Integrity, (Clause 7), as appropriate, as if ... |
1,524,312 | 1,524,317 | Why am I able to make a function call using an invalid class pointer | In below code snippet, although pointer is not initialized the call is still made successfully
temp *ptr;
ptr->func2();
Is it due to C++ language property, or it is VC++6 compiler which is foul playing?
class temp {
public:
temp():a(9){}
int& func1()
{
return a;
}
bool func2(int arg)
{
... | The C++ compiler doesn't prevent you from using uninitialised pointers, and although the results are undefined, it's normal for compilers in the real world to generate code that ignores the fact that the pointer is uninitialised.
It's one of the reasons why C++ is both fast and (comparatively) dangerous relative to som... |
1,524,356 | 1,524,510 | C++ deprecated conversion from string constant to 'char*' | I have a class with a private char str[256];
and for it I have an explicit constructor:
explicit myClass(const char *func)
{
strcpy(str,func);
}
I call it as:
myClass obj("example");
When I compile this I get the following warning:
deprecated conversion from string constant to 'char*'
Why is this happening?
| This is an error message you see whenever you have a situation like the following:
char* pointer_to_nonconst = "string literal";
Why? Well, C and C++ differ in the type of the string literal. In C the type is array of char and in C++ it is constant array of char. In any case, you are not allowed to change the characte... |
1,524,730 | 1,524,753 | C++ - when are non-pointers class member destroyed? | Suppose I have this code...
class GraphFactory : public QObject
{
private:
QMap<QString, IGraphCreator*> factory_;
public:
virtual ~GraphFactory();
};
GraphFactory::~GraphFactory()
{
// Free up the graph creators
QMap<QString, IGraphCreator*>::iterator itr;
for (itr = factory_.begin(); itr != fact... | It'll be destructed after the destructor code gets executed
The idea is to have access to your members in the destructor code so they get destroyed after it gets executed.
|
1,524,905 | 1,526,930 | Linux ioctl -> how to tell if current IP was obtained by dhcp | I'm fiddling with the sockets ioctl's to get the current interfaces setup and I can already get the IP, interface name, netmask and check if the interface is up or down, (I just do IOCTl to SIOCGIFCONF, SIOCGIFNETMASK and SIOCGIFFLAGS).
I am looking for a way to tell if my current IP address was obtained through dhcp ... | With the wide variety of DHCP clients on Linux -- pump, dhcpcd, dhclient, udhcpc, and quite possibly others that I do not know of -- this isn't possible in a general sense.
However, if you are targeting a specific distribution -- say, "default install of Ubuntu" -- then you can investigate solutions such as Stefan's. ... |
1,524,946 | 1,526,272 | UDP multicast using winsock API differences between XP and Vista | It seems to be that the implementation required to set up a UDP multicast socket has changed between windows XP and windows vista. Specifically:
Under windows XP, you must call bind() before you can reference any multicast-specific socket options.
However, under windows vista, you must not call bind() when dealing wit... | What error are you getting from the setsockopt() call that you make to apply IP_ADD_MEMBERSHIP and join the multicast group?
I've just run some tests here with my server framework and I note that I DO call bind() on Windows 7 (I don't have a Vista box to hand) and I can then also join a multicast group as expected as l... |
1,524,989 | 1,525,058 | separating compilation for to avoid recompilation when I add some debugging to .h file | I have a .h file which is used almost throughout the source code (in my case, it is just one directory with. .cc and .h files). Basically, I keep two versions of .h file: one with some debugging info for code analysis and the regular one. The debugging version has only one extra macro and extern function declaration.... | To avoid the issue with an external function , you could leave the prototype in both versions, it doesn't harm being there, if not used. But with the macro no chance, you can forget it, it needs recompilation for code replacements.
I would make intensive use of precompiled headers to fasten recompilation (as it cannot ... |
1,525,187 | 1,525,195 | How do we explain the result of the expression (++x)+(++x)+(++x)? | x = 1;
std::cout << ((++x)+(++x)+(++x));
I expect the output to be 11, but it's actually 12. Why?
| We explain it by expecting undefined behaviour rather than any particular result. As the expression attempts to modify x multiple times without an intervening sequence point its behaviour is undefined.
|
1,525,246 | 1,525,297 | How to set fixed axis intervals with Qt/QwtPlot? | I want to have a plotting widget in my Qt application. Qwt provides such a widget with QwtPlot. However, I can't find any way to only display a certain part of the complete range of my data.
Specifically, I want to display spectrums with a frequency range from 0 to 2^14. For the GUI however, only the audible range from... | Simple answer: Use QwtPlot::setAxisScale().
sorry for answering my own question.
|
1,525,284 | 5,795,889 | Mpeg 7 Descriptors in C++ | I need some descriptors of MPEG7 in C/C++. The descriptors are dominant color, color layout, color structure, scalable color, edge histogram and homogeneous texture. Do you know where can I find C/C++ source code for some of these these descriptors?
Thanks
| You can find the MPEG-7 feature extraction library and source code with OpenCV (2.2) at http://www.cs.bilkent.edu.tr/~bilmdg/bilvideo-7/Software.html
|
1,525,326 | 1,525,369 | Initializing temporary aggregate object using curly braces | Let's say I have a class:
class Aggregate {
public:
int x;
int y;
};
I know how to initialize an object using curly braces:
Aggregate a1 = { 1500, 2900 };
But I can't find a proper syntax to create temporary object and pass it as an argument to some method, for example:
void frobnicate(const Aggregate& arg... | What you want is possible with C++0x initializer lists.
class Aggregate {
public:
int x, y;
};
void frobnicate(const Aggregate& arg) {
}
int main() {
frobnicate({1, 2});
return 0;
}
GCC 4.4 already supports this with -std=c++0x flag. Possibly VS2010 CTP supports this too (correct me if I'm wrong).
With ... |
1,525,452 | 1,525,965 | Does anyone have experience with Clipsmm? | I have been looking at using CLIPS as an expert system for a simulator i am working on, and so i had a look at clipsmm. The only problem is that their sourceforge page has broken links and private forums.
I was just curious if anyone has had experience with clipsmm (i have learnt how to use CLIPS as a stand alone alrea... | Well, I don't have direct experience, but I happen to have been the original author of a very similar set of wrappers for Ada.
I developed what I needed for a school project, and released it to the Public Domain in hopes that somebody else could build on it or find it useful. Some folks have used it, but not enough to... |
1,525,456 | 1,525,642 | Converting Unicode to Multibyte | I have smalll problem i want to convert unicode into Multi byte is there any way
| std::string NarrowString(const std::wstring& str, const char* localeName = "C")
{
std::string result;
result.resize(str.size());
std::locale loc(localeName);
std::use_facet<std::ctype<wchar_t> >(loc).narrow(
str.c_str(), str.c_str() + str.size(), '?', &*result.begin());
return result;
}
It should use... |
1,525,535 | 1,525,546 | Delete all items from a c++ std::vector | I'm trying to delete everything from a std::vector by using the following code
vector.erase( vector.begin(), vector.end() );
but it doesn't work.
Update: Doesn't clear destruct the elements held by the vector? I don't want that, as I'm still using the objects, I just want to empty the container
| I think you should use std::vector::clear:
vec.clear();
EDIT:
Doesn't clear destruct the elements
held by the vector?
Yes it does. It calls the destructor of every element in the vector before returning the memory. That depends on what "elements" you are storing in the vector. In the following example, I am stori... |
1,525,580 | 1,525,698 | Is there a BinaryReader in C++ to read data written from a BinaryWriter in C#? | I've written several ints, char[]s and the such to a data file with BinaryWriter in C#. Reading the file back in (in C#) with BinaryReader, I can recreate all of the pieces of the file perfectly.
However, attempting to read them back in with C++ yields some scary results. I was using fstream to attempt to read back... | You realize that a char is 16 bits in C# rather than the 8 it usually is in C. This is because a char in C# is designed to handle Unicode text rather than raw data. Therefore, writing chars using the BinaryWriter will result in Unicode being written rather than raw bytes.
This may have lead you to calculate the offset ... |
1,525,658 | 1,525,803 | Decryption with AES and CryptoAPI? When you know the KEY/SALT | Okay so i have a packed a proprietary binary format. That is basically a loose packing of several different raster datasets. Anyways in the past just reading this and unpacking was an easy task. But now in the next version the raster xml data is now to be encrypted using AES-256(Not my choice nor do we have a choice). ... | AES-256 uses 256 bit keys. Ideally, each key in your system should be equally likely. A 63 byte string would be 504 bits. You first need to figure out how the string of 63 characters needs to be converted to 256 bits (The sample ones you gave are not base64 encoded). Next, "salt" isn't an intrinsic part of AES. You mig... |
1,525,764 | 16,634,045 | How to release pointer from boost::shared_ptr? | Can boost::shared_ptr release the stored pointer without deleting it?
I can see no release function exists in the documentation, also in the FAQ is explained why it does not provide release function, something like that the release can not be done on pointers that are not unique. My pointers are unique. How can I relea... | You need to use a deleter that you can request not to delete the underlying pointer.
See this answer (which has been marked as a duplicate of this question) for more information.
|
1,525,996 | 1,527,681 | How to Convert unicode version of ReadDirectoryChangesW | I need to convert Unicode version of ReadDirectoryChangesW to support multibyte is that possible
| You can cast a multi byte string into a unicode string by using this simple method
#include <string>
#include <sstream>
template <typename inputtype>
std::wstring toUTF16String(const inputtype& input)
{
std::wstringstream ss;
ss << input;
return ss.str();
}
Yo... |
1,526,053 | 1,527,321 | Constructing a C++ object (the MFC CRecordset) thread-safely | We're trying to build a class that provides the MFC CRecordset (or, really, the CODBCRecordset class) thread safety. Everything actually seem to work out pretty well for the various functions like opening and moving through the recordset (we enclose these calls with critical sections), however, one problem remains, a p... | You can make the CThreadSafeRecordset constructor private, then provide a public factory method that participates in your locking and returns an instance.
|
1,526,074 | 1,526,552 | How do I use C++ to acquire image from frame grabber? | I would like to know how is it possible to use a free C++ program to acquire image from a matrix vision frame grabber. Thanks.
| See http://www.matrix-vision.com/support/hardwareinfo.php?lang=en
|
1,526,531 | 1,526,915 | Wildcard search inside a Boost.MultiIndex data structure? | I'm trying to optimize my application by reducing round-trips to my database. As part of that effort, I've been moving some of the tables into memory, storing them as Boost.MultiIndex containers.
As a side-effect of this process, I've lost the ability to do wild-card matching on my strings. For example, when the tabl... | Well, first you don't actually have to use a boost::regex, if the wildcard is simple enough, you can get away by rolling you own unary operator. I would note that Boost.Regex is one of the few part of the library which actually requires to be linked (not header-only).
As for the problem of walking the whole structure, ... |
1,526,539 | 1,775,982 | VXL: Run-Time Check Failure #2 | With the VXL library:
I'm using vnl_conjugate_gradient with VC8 (visual studio 2005) and
occasionally I see this error in debug mode:
Run-Time Check Failure #2 - Stack around the variable 'z__' was corrupted.
This is happening while leaving the function cg_ in the file cg.c
This function is literally packed with "goto"... | That was due to the cost function returning NAN.
|
1,526,546 | 1,526,566 | C++ using list with count() function | I have a list L which needs to count how many 1s it has in it.
list<int> L;
L.push_back(14); L.push_back(5); L.push_back(22);
L.push_back(1); L.push_back(1); L.push_back(-7);
the function that i have been given is :
assert ( count(...,...,...) == 2);
i need to know what would replace the ...'s.
i have tried L.begin... | it should be std::count(L.begin(), L.end(), 1) so if this doesn't work all I can say is make sure you #include <algorithm>.
This code compiles for me in VS2008:
#include <list>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
list<int> L;
L.push_back(14); L.push_back(5); L.push_back(2... |
1,526,625 | 1,526,674 | Storing a list of classes and specialising a function by sub-classing in C++? | I'm trying to subclass a class with a specialisation of how I want a particular function to be performed. However, C++ implicitly converts my class to its base class when I store it in a list. Clearly the list could store any subclass of the class, so this is acceptable, but how would I go about storing the class so I ... | This is a phenomenon called slicing. The answer is to store a container of pointers instead, such as std::list<A*>. Just remember to delete everything when you're done.
If you can use the Boost libraries, there is a great library called Pointer Container which helps with this procedure.
|
1,526,792 | 1,526,820 | Help combining two functions in C++ | I need to combine these two functions.
and need help in so:
int Triangle(GzRender *render, int numParts, GzToken *nameList,GzPointer *valueList)
{
if (on_screen)
{
return Position(render, pos);
}
}
int Position(GzRender *render, GzCoord vertexList[3])
{
GzCoord *pv[3... | Normally, separating out functions is a better, more common practice (and one of the main tasks during refactoring). That being said, you can "combine" these simply by doing:
int Triangle(GzRender *render, int numParts, GzToken *nameList,GzPointer *valueList)
{
if (on_screen)
{
//function code... |
1,526,912 | 1,526,972 | Impossibly Fast C++ Delegates and different translation units | According to Sergey Ryazanov, his Impossibly Fast C++ Delegates are not comparable:
My delegates cannot be compared. Comparison operators are not defined because a delegate doesn't contain a pointer to method. Pointer to a stub function can be different in various compilation units.
To which one the readers have repl... | The code is both standard compliant, and fine. I don't see any place where he violates ODR, and it is true that all instantiations of a function template with the same template parameters should have "the same address" (in a sense that pointers to functions should all be equal) - how this is achieved is not important. ... |
1,526,982 | 1,527,164 | AIR(Flex) local socket connection | When connecting from a local AIR/Flex application to a local application (c++) using sockets do you still need a socket policy file? If you do, is there an easy way to load the policy file without sending the policy from the local application you are trying to connect to? side note: I am writing both applications.
| When connecting to another application on the localhost using sockets, you do not need to use a socket policy.
|
1,527,039 | 1,527,579 | How to write directly to linux framebuffer? | How to write directly to linux framebuffer?
| look at FBIOPUT_VSCREENINFO, ioctl and mmap
(I have the code but not at this pc, sorry)
edit: this should get you started
//open file descriptor and get info
inf fdScreen = open( "devicename", O_RDWR );
fb_var_screeninfo varInfo;
ioctl( fdScreen, FBIOGET_VSCREENINFO, &varInfo );
//set resolution/dpi/color depth/..... |
1,527,227 | 1,527,270 | C++ writing a modify_if function | I have a hw question which confuses me on what i have to do. The question is below:
The idea is to design a generic function called Modify_If that will take an input x (passed by reference), and two functors f1 and f2. The function Modify_If will use functor f1 to determine whether x obeys a certain condition. If it d... | template <class C, class Tester, class Transform>
void Modify_If(C& a, Tester f1, Transform f2) {
if (f1(a)) // Apply f1 to a - Check whether result is true
a = f2(a); // Transform with f2; save
}
|
1,527,367 | 1,527,401 | Redirect cout to a file vs writing to a file directly in linux | For C++/linux programs, how does writing to cout (when cout has been redirected to a file during program launch) compare against writing to the target file directly? (via say fstream)
Does the system do the appropriate magic at the start of the program to make these two cases exactly equivalent or is the later gonig to... | They are basically equivalent. In both cases, the underlying stream buffer will end up calling the write() system call, for the same effect.
Note however that by default, cout is synchronized to stdio, for backwards compatibility (so you can use C-style standard output as well as cout, and have it work as expected). ... |
1,527,383 | 1,527,756 | A way to destroy "thread" class | Here is a skeleton of my thread class:
class MyThread {
public:
virutal ~MyThread();
// will start thread with svc() as thread entry point
void start() = 0;
// derive class will specialize what the thread should do
virtual void svc() = 0;
};
Somewhere in code I create an instan... | Considering your additional requirements posted as comment to Checkers' reply (which is the
most straightforward way to do that):
I agree that join in DTor is problematic for various reasons. But from that the lifetime of your thread object is unrelated to the lifetime of the OS thread object.
First, you need to se... |
1,527,496 | 1,527,504 | Header file without source file | I have written the body of the function in the header file and so do not have a source file. when I tried running my project in visual studio .. I got an
error: Cannot open source file: No such file or directory.
How do I make visual studio understand that the definitions of the function are within the header itself?... | You need to create a dummy source.cpp file just containing #include "source.h"
edit - I just tried this - Visual studio will let you do.
test.cpp
#include "test.h"
where test.h
#include "stdio.h"
int main()
{
printf("hello world");
return 0;
}
Interesting - but pointless !
|
1,527,680 | 4,564,433 | Determining maximum possible alignment in C++ | Is there any portable way to determine what the maximum possible alignment for any type is?
For example on x86, SSE instructions require 16-byte alignment, but as far as I'm aware, no instructions require more than that, so any type can be safely stored into a 16-byte aligned buffer.
I need to create a buffer (such as... | In C++0x, the Align template parameter of std::aligned_storage<Len, Align> has a default argument of "default-alignment," which is defined as (N3225 §20.7.6.6 Table 56):
The value of default-alignment shall be the most stringent alignment requirement for any C++ object type whose size is no greater than Len.
It isn't... |
1,527,849 | 1,527,910 | How do you understand dependent names in C++ | I come across this term "dependent names" typically in the context of templates. However, I rarely touch the latter. Thus naturally would like to know more about the concept of dependent names.
How do you understand it in the context of templates and outside of them? example are critically encouraged!
| A dependent name is essentially a name that depends on a template argument.
When using templates there is a distinction between the point of definition of the template and the point of instantiation i.e. where you actually use the template. Names that depend on a template don't get bound until the point of instantiatio... |
1,527,969 | 1,527,985 | File echo loop with extra final iteration | Why do I get an extra iteration (extra line printed) when this code completes? Does there need to be an extra newline at the EOF? I would prefer not having to add extra/special characters to mark the EOF.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream... | try
while(infile>>text) cout << text << endl;
instead.
|
1,528,144 | 1,528,432 | OpenGL 3.2 Programming Guide? | Most resources available online are very outdated. Specifically, they are all about OpenGL 2 which matches to DirectX 9.
The current specification is 3.2 which is equivalent (or, well, very close) to DirectX 10 (11). But the specification itself is very hard to read. In contrast, DirectX SDK is a wonderful piece of doc... | The OpenGL Technical Wiki is a starting point. It also contains some OpenGL 3.2 tutorials. Don't expect anything like the DirectX SDK, but afaik there's no better resource. OpenGL learning seems to be more like a trial and error process, where the developer forum is especially helpful.
|
1,528,292 | 1,528,356 | C++: Casting for user defined types | How can I get the same handeling of casting for user-defined types as built in, eg:
float a = 5.4;
std::string s = a;//error, no conversion avaible
int x = a;//warning, possible data loss
int y = (int)a;//fine
int z = static_cast<int>a;//fine
float b = c;//warning, possible data loss
Now say I have my own Int and Floa... | I don't think there's a way, either. The best I could achieve is so that the line that you want to generate a warning doesn't compile at all.
class Int
{
public:
int value;
Int(int v);
};
class Float
{
public:
float value;
Float(float v);
operator int() { return static_cast<int>(value); }
};
int m... |
1,528,298 | 1,528,493 | Get path of executable | I know this question has been asked before but I still haven't seen a satisfactory answer, or a definitive "no, this cannot be done", so I'll ask again!
All I want to do is get the path to the currently running executable, either as an absolute path or relative to where the executable is invoked from, in a platform-ind... | There is no cross platform way that I know.
For Linux: pass "/proc/self/exe" to std::filesystem::canonical or readlink.
Windows: pass NULL as the module handle to GetModuleFileName.
|
1,528,359 | 1,542,559 | Floating point stack handling with floating-point exceptions turned on | I'm running into an issue with floating point exceptions turned on in Visual Studio 2005. If I have code like this:
double d = 0.0;
double d2 = 3.0;
double d3 = d2/d;
and if I register an SEH handler routine, then I can easily turn the div-by-zero into a C++ exception and catch it. So far so good.
However, when ... | While I can't find anything either, I can give some explanation as to the likely answer:
The ABI defines that upon a function call the stack should be empty, and it should be empty again on exit unless the return is a floating point value, where it would be the only item on the stack.
Since the exception handler must ... |
1,528,374 | 1,528,436 | How can I extend a lexical cast to support enumerated types? | I have the following function that will convert a string into a numeric data type:
template <typename T>
bool ConvertString(const std::string& theString, T& theResult)
{
std::istringstream iss(theString);
return !(iss >> theResult).fail();
}
This does not work for enumerated types, however, so I have done some... | You have to do two steps. Finding an integral type large enough to store the values. You could use unsigned long, but the values could be negative. Then you could use long but the values could extend into the range of unsigned long. So there is not really a fit-it-all type.
There is a trick though, by using overload r... |
1,528,419 | 1,528,511 | Templates and headers question | The compiler says it can't find the reference for the function when I do this:
// link.h
template <class T>
T *Link(T *&, T *(*)())
// link.cpp
template <class T>
T c:Link(T *&ChildNodeReference, T *(*ObjectCreator)()){
}
If I implement inside the class on the header it goes smoothly.
Please, I will work on the ... | Programming non-template code or non-inlined functions in headers is a Bad Thing™. The reason you have cpp files is to prevent redefinition of the same function code more than once, amongst other things.
The difference with templates is that the compiler practically doesn't touch them until your code instantiates a spe... |
1,528,567 | 1,528,635 | C++ templated functors | I was wondering if anyone can help me with functors. I dont really understand what functors are and how they work I have tried googling it but i still dont get it. how do functors work and how do they work with templates
| A functor is basically a "function object". It's a single function which you have wrapped in a class or struct, and which you can pass to other functions.
They work by creating your own class or struct which overloads the function call operator (called operator() ). Typically, you create an instance of it by simply con... |
1,528,685 | 1,532,179 | Qt QPlainTextEdit background | I want to change the background color of a QPlainTextEdit, how do I do this?
| Modify the palette of your plain text edit. Sample program:
#include <QApplication>
#include <QPlainTextEdit>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPlainTextEdit edit;
QPalette p = edit.palette();
p.setColor(QPalette::Active, QPalette::Base, Qt::red);
p.setColor(QPalette::Inact... |
1,528,691 | 8,508,658 | Idiomatic way to do list/dict in Cython? | My problem: I've found that processing large data sets with raw C++ using the STL map and vector can often be considerably faster (and with lower memory footprint) than using Cython.
I figure that part of this speed penalty is due to using Python lists and dicts, and that there might be some tricks to use less encumb... | Cython now has template support, and comes with declarations for some of the STL containers.
See http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#standard-library
Here's the example they give:
from libcpp.vector cimport vector
cdef vector[int] vect
cdef int i
for i in range(10):
vect.push_back(i)
for i... |
1,528,917 | 1,529,010 | Decrypting data files with wincrypt. Having trouble. Example shows CBase64Utils? | I need to decrypt some data files with wincrypt and examples are few and far between online. The most solid example I've found is here. However, this is using all sorts of types I cannot seem to find information about (CBase64Utils, CString, etc).
I am reading the final solution, trying to understand the process, and... | The code you linked is horrible. It appears the fellow wrote his encrypt method, and then subsequently wrote his decrypt method simply by copying and pasting the first method and making a few changes (yet leaving a ton of code left over from the encryption process). I wouldn't be surprised if it works, it's just that i... |
1,528,981 | 1,529,048 | Garbage values when C++ Operator Overloading | Im just getting garbage values. And it is wierd the debugger shows the correct values. But its printing weird stuff insted...
this frist part is fine. Essentially, It just takes me to my problem. I have what I need to print inside that h.hashtable[hashIndex] array.
ostream& operator<<(ostream& out, const hashmap& h)
{
... | Make sure the stream is set to print in decimal
out << dec << s.m_sharePrice;
(m_sharePrice is a non-pointer type, right?)
|
1,529,051 | 1,529,199 | can someone break this line apart gcc -E -dM - </dev/null | Just came across this guy that left me stunned:
gcc -E -dM - </dev/null
This part is confusing to me:
- </dev/null
| The "</dev/null" bit is at the shell level and not specific to gcc
< defines input file
> defines ouput file for std out,
>> defines a output for std out that will be appended to,
| sends std out output to another process on it's std in
I forget the syntax but you can also specify std err aswell like &2>
The name af... |
1,529,095 | 1,529,188 | String comparisons. How can you compare string with std::wstring? WRT strcmp | I am trying to compare two formats that I expected would be somewhat compatible, since they are both generally strings. I have tried to perform strcmp with a string and std::wstring, and as I'm sure C++ gurus know, this will simply not compile. Is it possible to compare these two types? Is there an easy conversion h... | You need to convert your char* string - "multibyte" in ISO C parlance - to a wchar_t* string - "wide character" in ISO C parlance. The standard function that does that is called mbstowcs ("Multi-Byte String To Wide Character String")
NOTE: as Steve pointed out in comments, this is a C99 function and thus is not ISO C++... |
1,529,208 | 1,529,290 | Invalid Algorithm Specified CryptoAPI | I am trying to decrypt something using 128BIT AES Decryption. When i attempt to calling CryptDecrypt i get an Error stating "Invalid Algorithm Specified". I get the same problem when using the library posted here: http://www.codeproject.com/KB/security/WinAES.aspx
What can cause this error?
I am using CryptoAPI along o... | Are you passing cryptoHandle by reference to InitWithCrypt? If not, your code
if(!CryptAcquireContextW(&cryptoHandle, ...
would only modify InitWinCrypt's copy of cryptoHandle.
EDIT: Given that it does, try getting rid of the CryptSetKeyParam call which sets CRYPT_MODE_CBC
|
1,529,269 | 1,529,274 | Illegal Argument Execv() Unix C++ | So I basically have a vector args with 1 argument per array that I'm trying to pass to an execv() call in unix.
Execv accepts two parameters like so: int execv(const char *path, char *const argv[]);
What's the best way to convert my vector of strings to an array of pointers ? Right now I'm doing the following but whe... | I think your problem may be that you are neglecting to put a NULL at the end of the array. Try this:
char * arg[args.size()+1];
arg[args.size()] = NULL;
for (int j=0; [...]
|
1,529,447 | 1,529,454 | Does return statement copy values | I am wondering about this because of scope issues. For example, consider the code
typedef struct {
int x1;/*top*/
int x2;/*bottom*/
int id;
} subline_t;
subline_t subline(int x1, int x2, int id) {
subline_t t = { x1, x2, id };
return t;
}
int main(){
subline_t line = subline(0,0,0); //is lin... | Yes, in that case there will be a copy made. If you change the function declaration like this:
subline_t &subline(int x1, int x2, int id) {
then no copy will be made. However, in your specific case it would not be valid to return a reference to an object allocated on the stack. The problem is that the object would be ... |
1,529,679 | 1,529,693 | How do you program safely outside of a managed code environment? | If you are someone who programs in C or C++, without the managed-language benefits of memory management, type checking or buffer overrun protection, using pointer arithmetic, how do you make sure that your programs are safe? Do you use a lot of unit tests, or are you just a cautious coder? Do you have other methods?
| All of the above. I use:
A lot of caution
Smart Pointers as much as possible
Data structures which have been tested, a lot of standard library
Unit tests all the time
Memory validation tools like MemValidator and AppVerifier
Pray every night it doesn't crash on customer site.
Actually, I am just exaggerating. Its no... |
1,529,717 | 1,529,735 | Variable parameter lists in C++ and C | I'm working on rewriting a C program in C++ to take advantage of OO aspects so it can easily support multiple devices, and one part of the program is an expression evaluator. Expressions can have function calls, and here's the structure for functions.
typedef struct {
char *name;
int argc;
void (*func) ();
... | The var args are what you are looking for. It works both in C and C++. This is what is used for printf() for example :).
You can find more information by googling va_arg (one of the function used for variable number of arguments)
var ags on cpppreference.com
var ags on cplusplus.com
|
1,529,942 | 1,529,960 | Explicit Linking DLL and Program Hangs | I've the following piece of code in my program which dynamically links wtsapi32.dll file for session notifications like WTS_SESSION_LOCK and WTS_SESSION_UNLOCK and runs in background. After the first lock/unlock the program hangs and not responding.
Is this a right way of doing explicit linking ?
void RegisterSes... | I'd say you probably cannot safely call FreeLibrary like that - you will be unloading the code you want to have call you. You should probably ensure not to free the dll until after you are finished getting notifications.
|
1,530,019 | 1,530,074 | Monitor the data in a table | How to write a shell script/process which runs like a daemon on Unix and continuously monitors a field in the table and sleeps for 30 sec's. The field value will regularly increase to a maximum value and my process/script which is monitoring will provide a simple select query output to a log file. any approach is prefe... | Write a trigger on the table; on the value you care about, log it to another table; select from the other table at your leisure.
|
1,530,245 | 1,530,262 | I heard that Python has automated "garbage collection" , but C++ does not. What does that mean? | I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?
| That means that python user doesn't need to clean his dynamic created objects, like you're obligated to do it in C/C++.
Example in C++:
char *ch = new char[100];
ch[0]='a';
ch[1]='b';
//....
// somewhere else in your program you need to release the alocated memory.
delete [] ch;
// use *delete ch;* if you've initializ... |
1,530,330 | 1,530,469 | Why/how does this compile? | C++ in MS Visual Studio 2008. Warning level 4 plus a load of extra warnings enabled as well. I'd expect this to give a warning at least, but more likely a compiler error?
Function declaration is as follows:
int printfLikeFunction(
const int bufferLength,
char * const buffer,
const char... | C++ has a special loophole for string literals for compatibility with pre-const C-style code. Although string literals are arrays of const char, they can be converted to a pointer to non-const char.
Paraphrasing 4.2/2 [conv.array]: a 'narrow' string literal can be converted to an rvalue of type pointer to non-const cha... |
1,530,531 | 1,530,542 | C++ returning queue pointer from function error | I have a function
queue< pair<int,int> > * factorize(int n) {
...}
It shows this compile error.
generatePrimes.cpp:20: error: expected constructor, destructor, or type conversion before '<' token
generatePrimes.cpp:20: error: expected `,' or `;' before '<' token
What's wrong?
| Either you don't include necessary header files (queue and utility), or don't have using namespace std or both.
To overcome the first problem include the headers. To overcome the second one either add using or provide fully qualified names (std::queue and std::pair).
|
1,530,561 | 1,530,749 | Set location of MessageBox? | I want to print out a message using MessageBox (or similar). I would also like control over where exactly on the screen the box appears but can find nothing in the description of MessageBox that allows you control over the location. Did I miss something? If MessageBox can not be used, then is there an alternative?
For ... | Step 1: Create a CBT hook to trap the creation of the message box:
// global hook procedure
HHOOK hhookCBTProc = 0;
LRESULT CALLBACK pfnCBTMsgBoxHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
CREATESTRUCT *pcs = ((CBT_CREATEWND *)lParam)->lpcs;
if (pcs->style & WS_DLGFRAME ... |
1,530,579 | 1,530,633 | C++ specialization, type_of or just typeid | I would like to know what is better to use in my situation and why. First of all I heard that using RTTI (typeid) is bad. Anyone could explain why? If I know exactly types what is wrong to compare them in a runtime? Furthermore is there any example how to use boost::type_of? I have found none searching through the migh... | It's bad because
A, B and C are known at compile-time but you're using a runtime mechanism. If you invoke typeid the compiler will make sure to include metadata into the object files.
If you replace "Do this chunk of code related to A type" with actual code that makes use of CSomeClass's interface you'll see you won't... |
1,530,654 | 1,530,664 | What is the output of this program? | when i tried to run compile and execute this statement in a simple c file:
main(){ printf("%d");}
on HP it's is giving me 64 and on AIX its giving me 804359524.
Could anyone tell me what is this behavior.
| I assume you mean:
int main()
{
printf("%d");
}
That being the case, printf() is reading an int (as directed by the format specifier %d) from the stack. Since you've not specified one, it's just reading whatever is on the stack and using that. Hence, your seeing pseudo-random output.
Instead, try:
int main()
{
pri... |
1,530,752 | 1,530,781 | What does the C++ error message "<near match>" mean? | When compiling my code with the GNU C++ compiler I get something like
bla.cxx: In function `int main(int, const char**)':
bla.cxx:110: error: no matching function for call to `func(const classA*&, const classB<classC>*&) const'
someheader.h:321: note: candidates are: bool func(const classA*, const T*&, const std::strin... | I normally see <near match> when a possible method matches except for const. Maybe the strings are optional arguments in this case? In that case the problem is that you have a const object, and are trying to call a non-const method.
NB: I haven't ever looked at the compiler code, merely looked at error messages gcc has... |
1,530,765 | 1,530,816 | Why use Visual Studio 6 for C++ | I am just wondering why programmers who program in C++ for windows always use Visual Studio 6 instead of Visual Studio 2008?
Isn't the compiler in 2008 much better than the one in VS6?
The reason I ask as I have used many sdk's that are always written in VS6?
Many thanks,
Steve
| Partly it may be because earlier compilers are often (though not always) faster than later, and more feature-rich/standards-compliant, ones. I don't know whether this applies with VC6 vs later, but it may well do.
In the case of VC6 I think the two major factors are that the IDE is much faster to use than any of the pa... |
1,531,023 | 1,531,080 | moving a point in 3d space | I have a point at 0,0,0
I rotate the point 30 deg around the Y axis, then 30 deg around the X axis.
I then want to move the point 10 units forward.
I know how to work out the new X and Y position
MovementX = cos(angle) * MoveDistance;
MovementY = sin(angle) * MoveDistance;
But then I realised that these values will ch... | You should multiply point coordinates to full rotation matrix, which is matRotationTotal = matRotationX * matRotationY * matRotationZ. Check this article for details.
|
1,531,294 | 1,531,332 | Unusual destructor behaviour when copying over stack variables | I wrote a test to check whether destructors were called before an overwriting assignment on a stack variable, and I can't find any rational explanation for the results...
This is my test (in Visual C++ 2008 Release mode):
#include <iostream>
class C {
public:
char* ptr;
C(char p) { ptr = new char[100]; ptr[0] = p;}
... | Rule of Three
Your application behavior is undefined, since as stated multiple objects will share access to a common pointer and will attempt to read it...
The rule of three states that each time you define one of:
copy constructor
assignment operator
destructor
Then you should define the other, since your object has... |
1,531,706 | 1,531,816 | Ternary operator on auto_ptr content not working | I initialize an auto_ptr to NULL and later in the game I need to know if it has NULL or not to return it or a new copy.
I've tried this
auto_ptr<RequestContext> ret = (mReqContext.get() != 0) ? mReqContext : new RequestContext();
And several other similar stuff casting and so, but g++ tries to invoke auto_ptrs nonexis... | I suppose the situation is analogous to the following:
#include <iostream>
#include <memory>
int main()
{
std::auto_ptr<int> a(new int(10));
std::auto_ptr<int> b = a.get() ? a : new int(10);
}
And here's Comeau's very enlightening error message:
"ComeauTest.c", line 7: error: operand types are incompatible ("... |
1,532,293 | 1,534,062 | How do I retrieve a process ID for the Win32 Windows Mobile platform? | I would like to retrieve the process ID and handle of a process by querying for it by process name. Is this possible to do on the Win32 Windows Mobile platform?
Thanks in advance.
| Use CreateToolhelp32Snapshot(), following with Process32First() and the related functions, following the general idea in the code sample. The Process32... functions provide PROCESSENTRY32 for each process, which contains the Process ID.
|
1,532,550 | 1,536,688 | Using Boost Graph to search through a DAG Graph? | I need to search through a DAG graph, but I don't want to advance past a node before I have seen all of the other nodes that have directed links pointing to it.
Is there an existing algorithm to handle this particular situation, the depth first search and breath first search don't work for this order of traversal.
Ie:
... | So my latest thoughts are to do a topological sort over the entire graph whenever an edge is added or removed and store the order of immediate child nodes to be traversed for each node (which may be a bit of a tricky algorithm to write).
Then I do a modified breadth first search (as suggested by chaos), and in the foll... |
1,532,640 | 1,533,222 | Which iomanip manipulators are 'sticky'? | I recently had a problem creating a stringstream due to the fact that I incorrectly assumed std::setw() would affect the stringstream for every insertion, until I changed it explicitly. However, it is always unset after the insertion.
// With timestruct with value of 'Oct 7 9:04 AM'
std::stringstream ss;
ss.fill('0'); ... | Important notes from the comments below:
By Martin:
@Chareles: Then by this requirement all manipulators are sticky. Except setw which seems to be reset after use.
By Charles:
Exactly! and the only reason that setw appears to behave differently is because there are requirements on formatted output operations to ... |
1,532,665 | 1,532,904 | JNI Pass By Reference, Is it Possible? | I have a Java program that calls a C++ program to authenticate users. I would like the program to return either true or false, and if false, update a pointer to an error message variable that i then can grab from the Java program.
Another explination:
The native method would look something like this:
public native Stri... | There is a common technique to simulate additional out parameter by using object array in parameter.
For example.
public native String takeInfo(String nt_domain, String nt_id, String nt_idca, String nt_password, String[] error);
boolean canLogin = takeInfo(domain, userID, "", userPass, error);
if(!canLogin){
String... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.