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,765,539
1,766,019
Declaring function objects for comparison?
I have seen other people questions but found none that applied to what I'm trying to achieve here. I'm trying to sort Entities via my EntityManager class using std::sort and a std::vector<Entity *> /*Entity.h*/ class Entity { public: float x,y; }; struct compareByX{ bool operator()(const GameEntity &a, const GameEnt...
And a third one comes in... After you edited you question, still one open topic: your comparator takes a const & to the GameEntity class. It should, in order to work with the values of the vector<GameEntity*>, take const GameEntity* arguments instead.
1,765,558
1,765,570
C++ String manipulation - if stament
I have the following code that works correctly. However after I add an else statement anything always evaluates to else wgetstr(inputWin, ch); //get line and store in ch variable str = ch; //make input from char* to string if(str=="m" || str=="M"){ showFeedback("Data Memory Update...
All of those are separate if-statements. The else you added only goes with the last one. Change all but the first if to else if and it should work like you expect.
1,765,776
1,777,284
Soundflower input applications
I've downloaded the source of Soundflower and I am trying to retrieve a list of all applications currently sending data to Soundflower. I'd like to manipulate each application's sound separately just like JACK and Audio Hijack does. Any ideas?
Unfortunately, this isn't something you're going to be able to find out from within the Soundflower kext because applications don't connect directly to audio drivers. The Audio HAL is an audio driver's user client and manages audio input and output between apps and the kernel. You should look into using a HAL Plug-in...
1,766,014
1,768,042
Are double* and double** blittable types? C#
I have a question regarding marshalling of C++ arrays to C#. Does the double* automatically convert to double[]? I know double is a blittable type, so double from C++ is the same as double from C#. And what about double**, does it convert to double[,] ? I have the following unmanaged function: int get_values(double**...
The declaration makes no sense. It would make sense if the function takes a pointer to an array of doubles, but then the declaration would be int get_values(double* array, int size); Where size would give the size of the array allocated by the client and the function's return value indicates how many doubles were act...
1,766,134
1,766,161
array reallocation C++
Suppose you have an array, items, with capacity 5 and suppose also you have a count varaible that counts each entry added to the array. How would you realloacte the array? Using C++ syntax? void BST::reallocate() { item *new_array = new item[size*2]; for ( int array_index = 0; array_index < size * 2; array_index+...
Your old array items has only size elements, so you need to change the upper limit in your for loop to size from size*2 when you're copying the old elements to the new array.
1,766,150
1,766,164
C++ convert int and string to char*
This is a little hard I can't figure it out. I have an int and a string that I need to store it as a char*, the int must be in hex i.e. int a = 31; string str = "a number"; I need to put both separate by a tab into a char*. Output should be like this: 1F a number
With appropriate includes: #include <sstream> #include <ostream> #include <iomanip> Something like this: std::ostringstream oss; oss << std::hex << a << '\t' << str << '\n'; Copy the result from: oss.str().c_str() Note that the result of c_str is a temporary(!) const char* so if your function takes char * you will n...
1,766,275
1,767,356
How to obtain the PIDL of an IShellFolder
If I have an IShellFolder interface pointer. How might I obtain its PIDL? I can see how to enumerate its children, and I can see how to use it to compare any two children. But how might I get its own pidl? I ask because I'd like to know: Is this IShellFolder == Another IShellFolder I can use IShellFolder::CompareI...
I found that you can query an IShellFolder for its IPersistFolder2, which has GetCurFolder(), which returns its absolute PIDL. I could then simply use the IShellFolder for the desktop to CompareIDs() to determine if they're equal. I found the outlines of this while looking at SHGetIDListFromObject. I couldn't just u...
1,766,351
1,766,547
Causing push_back in vector<int> to segmentaion fault on what seems to be simple operation
I'm working on a program for Project Euler to add all the digits of 2^1000. So far I've been able to track the program segmentation faults when it reaches around 5 digits and tries to push a one onto the vector at line 61 in the function carry(). #include <iostream> #include <vector> #include <string> using namespace...
void MegaNumber::multiplyAssign(int operand, int index) { data[index] *=operand; if(index<data.size()) multiplyAssign(operand, index+1); if(data[index] > 9) carry(index); } index is 0 based, while data.size() is 1 based so to say, meaning data.size() returns number 1 greater than the largest valid index. S...
1,766,711
1,766,764
Enum declaration inside a scope that is a parameter of a macro
I am trying to create a macro that takes a scope as a parameter. I know, it is probably not a good thing etc etc. I was trying this and got the problem that preprocessor looks for commas and parentheses... the problem is with enum. How would I declare a enum inside a scope that is a parameter of a macro? when the c...
It sounds like you are pushing the preprocessor beyond where it's willing to go. While it's not as elegant, how about breaking your macro in two (one pre- and one post-) and rather then passing a "scope" as parameter, you surround your scope with you pre- and post- macros. So, if your macro looks something like: SOMAC...
1,766,743
1,766,884
wxWidgets and "Implement_App" causes _main duplicate symbol error
I'm compiling a trivial wxWidgets app on MacOS X 10.6 with XCode 3.2 The linker is return an error about the symbol _main being defined twice: once in main.mm once in the test_app.cpp file. After I commented out the macro: Implement_App(TestApp) The error went away, compiled & linked and I was able to run the a...
IMPLEMENT_APP is a macro used in wxWidgets to create an entry point to the program without worrying about whether the program will be compiled on Windows, Mac, *nix, or whatever. As a result of this, IMPLEMENT_APP has to define main (or its equivalent, such as WinMain). You might find the IMPLEMENT_APP_NO_MAIN macro t...
1,767,449
1,767,471
C++ HTTP / HTML Socket Question
I'm building an application which I'd like to have it connect to a website and parse some data off it. I'm wondering if anyone could provide me some raw example code. I don't necessarily need help parsing, I'm just wondering in C++ how would I go about downloading the data from the page into my app so that I can start ...
Check out boost.asio [examples].
1,767,458
1,767,514
Modeling "optional" inheritance
I'm having trouble deciding on a way to model this type of relationship... All bosses can do certain things and have certain things (velocities, health, etc.) so these are part of the "main" abstract boss class. class Boss // An abstract base class { //Stuff that all Bosses can do/have and pure virtual functions };...
I think you need to look into Mixin classes. For example, you could create the following classes: class Boss { // Here you will include all (pure virtual) methods which are common // to all bosses, and all bosses MUST implement. }; class Shooter { // This is a mixin class which defines shooting capabilitie...
1,767,479
1,767,544
WriteFile function "freezes"
I'm trying rewrite xCmd which can start a process on a remote machine. Basically it installs itself as a service on the target computer and then starts the requested process. Everything is working fine, but i noticed an error. xCmd is communicating through pipes, and it uses WriteFile(). My problem is, that if i run my...
I think that means that the other end of the pipe connection is not reading data out of the pipe and the pipe buffer is full. It may also indicate that the other end has closed their pipe handle. For anonymous pipes that would cause an error when you try to write, but I don't remember if that's also true with named pi...
1,767,670
1,767,691
Is it possible to stack Yacc grammar rule code?
Lets say I need to run some initialization code everytime I match a rule how can I reduce the redundancy? rule : TOKEN1 { init(); token1Code(); } | TOKEN2 { init(); token2Code(); } ; Also is it possible to do something like rule : TOKEN1 | TOKEN2 { codeForToken1OrToken2(); } ;
You can use something like: rule : { init(); } real_rule { codeForToken1or2(); } ; real_rule : TOKEN1 { token1Code(); } | TOKEN2 { token2Code(); } ; But this may introduce conflicts, depending on how 'rule' is used.
1,767,679
1,769,296
Incomplete Type memory leaks?
Microsoft Visual Studio 2008 is giving me the following warning: warning C4150: deletion of pointer to incomplete type 'GLCM::Component'; no destructor called This is probably because I have defined Handles to forward declared types in several places, so now the Handle class is claiming it won't call the destructor on ...
It often happen when using Pimpl, so I'll focus on the solution there: class FooImpl; class Foo { public: // stuff private: Pimpl<FooImpl> m_impl; }; The problem here is that unless you declare a destructor, it will be automatically generated, inline, by the compiler. But of course, the compiler will have no idea...
1,767,919
1,767,937
std vector + default allocator + direct array access?
If I create a std::vector with the default allocator like this: vector<int> myVec = vector<int>(); myVec.push_back(3); myVec.push_back(5); myVec.push_back(8); Does the vector then store the actual data internally into an array of int? Is it possible to get a pointer to this array and iterate directly over it using th...
Yes, vector is designed so you can do this, use &myVec[0] to get an int*. You can also use vector's iterator type, which behaves similarly. (Pointers are valid random-access iterators.) That you're using the default allocator, or any other allocator, doesn't change any of this, it's a required part of vector's inter...
1,768,075
1,768,100
Is it a good idea to put all project headers into one file HEADERS.h?
I talked to my instructor the other day and asked him this question. He told me that I could go for smaller projects, but I'm starting a chess program and I was wondering what Stack Overflow thinks about this issue. Should I include all headers into one file, or separate them?
Normally, you want separate headers. Including more than necessary does a few potentially bad things. This is single greatest cause of slow compile times. Unnecessary inclusion of extra headers slows down compilation, since each source file has to worry about more info than it needs. It starts as a small problem, and...
1,768,294
1,768,382
How to allocate a 2D array of pointers in C++
I'm trying to make a pointer point to a 2D array of pointers. What is the syntax and how would I access elements?
By the letter of the law, here's how to do it: // Create 2D array of pointers: int*** array2d = new (int**)[rows]; for (int i = 0; i < rows; ++i) { array2d[i] = new (int*)[cols]; } // Null out the pointers contained in the array: for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { array2d[i][j] =...
1,768,477
1,768,492
Finding bugs in Subversion's mixed revision working copies
The project I work on has recently been switched from a horribly antiquated revision control system to Subversion. I felt like I had a fairly good understanding of Subversion a few years ago, but once I learned about Mercurial, I forgot about Subversion quickly. My question is targeted at those who work with a sizable...
Since you committed all your work in progress, you have no reason not to update your copy with the entire latest revision. The lengthy compile is part of the price of a large project. The compile time is almost always less than the time spent trying to determine whether you have a bug, or whether there's some obscur...
1,768,651
1,809,209
SMART ASSERT for C++ application?
Is it good to define a new macro that craters my need of showing failed assertion to user and with just enough information for developers to debug the issue. Message for user, what the user should do with this message at last information for the developer #define ASSERT(f) \ do \ { \ if (!(f) && AfxAss...
There's a couple things I would consider from the end-user's standpoint. Who is the target audience? If your grandmother is using this program, would these assertion messageboxes accomplish anything beyond frustrating her? How frequently would these assertions fail? One assertion during a week of normal usage would ...
1,768,834
1,768,923
Determine Parent Class from boost::any
May I know is there any way to determine parent class from boost::any? #include <iostream> #include <boost/any.hpp> class a { public: virtual ~a() {} }; class b : public a { }; bool is_class_a(const boost::any& any) { return boost::any_cast<a>(&any) != 0; } bool is_class_a_v2(const boost::any& any) { tr...
boost::any was designed so that it holds strongly informational objects for which identity is not significant. If you want to work with polymorphic types then you could use pointers to base class or boost::shared_ptr with base class instead of boost::any.
1,768,991
1,769,417
Cross platform unicode path handling
I'm using boost::filesystem for cross-platform path manipulation, but this breaks down when calls need to be made down into interfaces I don't control that won't accept UTF-8. For example when using the Windows API, I need to convert to UTF-16, and then call the wide-string version of whatever function I was about to c...
Well the simplest way would be to make some kind of generic routine that would return string encoded the way you'd want for provided path or a wrapper class around the path. boost::filesystem::wpath boostPath( L"c:\\some_path" ); MyPathWrapper p( boostPath ); std::wstring sUtf8 = p.file_string_utf8(); std::wstring sUtf...
1,769,023
1,783,458
Is there any regular expression engine that does Just-In-Time compiling?
My Questions is Is there any regular expression engine that does Just-In-Time compiling during regex pattern parsing and use when matching / replacing the texts? Or where can I learn JIT for i386 or x64 architecture? Why I need it I was recently trying to benchmark Python’s built-in regex engine compared with normal C ...
The only regex engine that I know that can compile regular expressions into executable code is the one in .NET when you pass RegexOptions.Compiled. That causes the Regex class to emit MSIL which can then be JITted like any other .NET code. Whether than makes the .NET regex engine faster than others is a totally differ...
1,769,350
1,770,325
IO Completion ports: How does WSARecv() work?
I want to write a server using a pool of worker threads and an IO completion port. The server should processes and forwards messages between multiple clients. The 'per client' data is in a class ClientContext. Data between instances of this class are exchanged using the worker threads. I think this is a typical scenari...
(1) The first problem is that the server basically receives data from clients but I never know if a complete message was received. Your recv calls can return anywhere from 1 byte to the whole 'message'. You need to include logic that works out when it has enough data to work out the length of the complete 'mess...
1,769,627
1,769,642
concept question about dll
My boss asks me to create a dll file using C++. The dll file needs to do the following: create a blank area in Window create some simple shapes (for an example, a rectangle) on the blank area control the locations of the shapes in the blank area I am new to C++, so please correct me if my understand is incorrect Dll ...
the DLL should be called from some executable and the dll can also call other dll's functions. While creating a dll, you need to create an executable to test the dll, and you can use other dll by dynamically loading or using its .lib in the project.
1,769,731
1,770,899
How to set auto=repeat on a qaction in a qtoolbar?
I'd like to use the autorepeat feature of the QToolButton class. The problem is that the instances are created automatically when using QToolBar::addAction() and I can't find a way to reach them: QToolBar::widgetForAction() doesn't seem to work in that case (always returns NULL). Any ideas? Thanks
There seem to be no simple way. The best I found is to use QObject::findChldren : foreach(QToolButton* pButton, pToolBar->findChildren<QToolButton*>()) { if (pButton->defaultAction() == pTheActionIWant) { ... } }
1,770,081
1,770,154
Initialising arrays in C++
Everywhere I look there are people who argue vociferously that uninitialised variables are bad and I certainly agree and understand why - however; my question is, are there occasions when you would not want to do this? For example, take the code: char arrBuffer[1024] = { '\0' }; Does NULLing the entire array create a ...
I assume a stack initialization because static arrays are auto-initialized. G++ output char whatever[2567] = {'\0'}; 8048530: 8d 95 f5 f5 ff ff lea -0xa0b(%ebp),%edx 8048536: b8 07 0a 00 00 mov $0xa07,%eax 804853b: 89 44 24 08 mov %eax,0x8(%esp) 80485...
1,770,090
1,770,175
What C++ tutorial would you recommend for an experienced programmer that has some patchy knowledge about the language?
In my early days of programming, before I started working professionally, I wrote a fair share of trinket/exercise apps in C++ and felt fairly confident that I know the language. Then, as opportunity came, I went to do real work and left the C/C++ world. For the past 5 years I've written tons of code in C# and have had...
C++ is too complex to be learned through tutorials, you could only scratch the surface that way. Especially the advanced usage of the STL (and templates in general) is usually beyond the scope of online tutorials. Therefore, I would recommend books: Stroustrup's "The C++ Programming Language", and Scott Meyer's "Effect...
1,770,471
1,770,491
Is it possible to use a RA-iterator out of range?
Consider the following code: typedef std::vector<int> cont_t; // Any container with RA-iterators typedef cont_t::const_iterator citer_t; // Random access iterator cont_t v(100); const int start = 15; // start > 0. citer_t it = v.begin() - start; // Do not use *it int a1 = 20, b1 = 30; // a1, b1 >= start int a2 = 30, ...
You'll get assertion condition here according to C++ Standard 24.1.5 Table 76.
1,770,636
1,770,688
shared_ptr vs scoped_ptr
scoped_ptr is not copy able and is being deleted out of the scope. So it is kind of restricted shared_ptr. So seems besides the cases when you really need to restrict the copy operation shared_ptr is better to use. Because sometimes you don’t know you need to create a copy of your object or no. So the question is: besi...
shared_ptr is more heavyweight than scoped_ptr. It needs to allocate and free a reference count object as well as the managed object, and to handle thread-safe reference counting - on one platform I worked on, this was a significant overhead. My advice (in general) is to use the simplest object that meets your needs. I...
1,770,670
1,782,818
How do I control the text input panel programmatically (TabTip.exe) in Windows Vista/7
I'm adapting an application for touch screen interface and we want to use the tablet text input panel included in Windows Vista/7, specifically its keyboard. I want to show and hide it as appropriate for my app. Basically I want ShowKeyboard() and HideKeyboard() functions. What's the best way to control this? I looked ...
I solved the problem. It turns out that Spy++ really is a Windows programmers best friend. First, the window class of the input panel window turns out to be "IPTip_Main_Window". I use this to get the window handle like so: HWND wKB = ::FindWindow(_TEXT("IPTip_Main_Window"), NULL); It turns out that I can just post th...
1,770,702
1,770,735
Is it difficult to port C++ to C++/CLI?
I suppose you cannot simply compile a C++ application with a C++/CLI compiler. I am wondering if it would be difficult. Has anybody tried this, and if so: were there a lot of modifications needed?
The situation is a bit like compiling C as C++. Most C will compile as C++, but is a long ways from what you'd think of as exemplary C++, so chances are that you'd want to modify it (often quite a bit) before you used it. Likewise, most C++ will compile as C++/CLI, but chances are that you'd rather not really use it th...
1,770,707
1,771,116
How do you add a repeated field using Google's Protocol Buffer in C++?
I have the below protocol buffer. Note that StockStatic is a repeated field. message ServiceResponse { enum Type { REQUEST_FAILED = 1; STOCK_STATIC_SNAPSHOT = 2; } message StockStaticSnapshot { repeated StockStatic stock_static = 1; } required Type type = 1; opti...
No, you're doing the right thing. Here's a snippet of my protocol buffer (details omitted for brevity): message DemandSummary { required uint32 solutionIndex = 1; required uint32 demandID = 2; } message ComputeResponse { repeated DemandSummary solutionInfo = 3; } ...and the C++ to fill up Com...
1,770,725
2,186,475
Pointers to members in swig (or Boost::Python)
I made some bindings from my C++ app for python. The problem is that I use pointers to members (It's for computing shortest path and giving the property to minimize as parameter). This is the C++ signature: std::vector<Path> martins(int start, int dest, MultimodalGraph & g, float Edge::*) This is what I did (from what...
Don't know about SWIG, but in boost::python you can write a wrapper: bool foo(int x, float* result); boost::python::tuple foo_wrapper(int x) { float v; bool result = foo(x, &v); return boost::python::make_tuple(result, v); } BOOST_PYTHON_MODULE(foomodule) { def("foo", &foo_wrapper); } And in python y...
1,770,763
1,771,043
boost to_upper function of string_algo doesn't take into account the locale
I have a problem with the functions in the string_algo package. Consider this piece of code: #include <boost/algorithm/string.hpp> int main() { try{ string s = "meißen"; locale l("de_DE.UTF-8"); to_upper(s, l); cout << s << endl; catch(std::runtime_error& e){ cerr << e.what() << endl...
std::toupper assumes a 1:1 conversion, so there is no hope for the ß to SS case, Boost.StringAlgo or not. Looking at StringAlgo's code, we see that it does use the locale (Except on Borland, it seems). So, for the other case, I'm curious: What is the result of toupper('ó', std::locale("es_CO.UTF-8"))on your platform? W...
1,770,780
1,770,892
How to connect to MySQL Database from eMbedded Visual C++
How can I connect to a remote Mysql database, from Cpp code using Microsoft eMbedded Visual C++ (which is configured for a special board running WindowsCE)? I have downloaded the source files for Mysql C and C++ Connector/APIs but; their 'make' or installation process is pretty complicated and valid only for Visual Stu...
I have found that, there are no ports of mysql-client to any mobile platform. If anyone has any other information, please feel free to answer this question.
1,770,808
1,773,410
Refactoring function pointers to some form of templating
Bear with me as I dump the following simplified code: (I will describe the problem below.) class CMyClass { ... private: HRESULT ReadAlpha(PROPVARIANT* pPropVariant, SomeLib::Base *b); HRESULT ReadBeta(PROPVARIANT* pPropVariant, SomeLib::Base *b); typedef HRESULT (CMyClass::*ReadSignature)(PROPVARIANT* pPropVar...
Ok, my previous visitor approach is a history. I am going to post you entire text of small working program that you can play with. Assuming that _pFile->formatA() _pFile->formatC() _pFile->formatD() All declared as FormatA* formatA() FormatC* formatC() FormatD* formatD() In other words return type is known at compil...
1,771,096
1,772,711
Grabbing memory from another process
in Windows, lets say I have used DLL Injection to get into another process. I have also done some screencaptures of the memory on the process I have injected into and know the location of the data I want to pull out. Lets say there is data in the other process at 0xaaaaaaaa that contains a certain value. How do I grab ...
You should be able to use the ReadProcessMemory function. See also How to write a Perl, Python, or Ruby program to change the memory of another process on Windows?
1,771,117
1,771,232
Why doesn't C++ reimplement C standard functions with C++ elements/style?
For a specific example, consider atoi(const std::string &). This is very frustrating, since we as programmers would need to use it so much. More general question is why does not C++ standard library reimplement the standard C libraries with C++ string,C++ vector or other C++ standard element rather than to preserve th...
Another more general question is why do not STL reimplementate all the standard C libraries Because the old C libraries do the trick. The C++ standard library only re-implements existing functionality if they can do it significantly better than the old version. And for some parts of the C library, the benefit of wri...
1,771,156
1,771,251
AVL Tree Code - I don't understand
void insert( const Comparable & x, AvlNode * & t ) { if( t == NULL ) t = new AvlNode( x, NULL, NULL ); else if( x < t->element ) { insert( x, t->left ); if( height( t->left ) - height( t->right ) == 2 ) if( x < t->left->element ) ...
It's not 100% clear what you're asking. The code AvlNode * & t declares t to be a reference to a non-const pointer. So, the function insert may change the pointer object of the caller. Since pointers may be null the code probably uses a function called height as a shortcut to handle the special case of null pointers: ...
1,771,222
1,771,402
Effect of exit function in Windows Service Programs
I have a program that is a windows service. It is started by StartServiceCtrlDispatcher function. It's network server that accepts user's inputs as command for controlling purposes. Now, I want it to have the ability to be shutdown by users, i.e. when user type a "quit" command, the service will stop. (Don't worry abou...
You should use the ControlService() function to stop the service, and then return from program flow normally if this should also cause the process to exit. ControlService Function @ MSDN exit() will cause process termination, which will definitely kill a process that hosts 1 service. However, this is undesirable for st...
1,771,302
1,771,347
Efficient passing of std::vector
When a C++ function accepts an std::vector argument, the usual pattern is to pass it by const reference, such as: int sum2(const std::vector<int> &v) { int s = 0; for(size_t i = 0; i < v.size(); i++) s += fn(v[i]); return s; } I believe that this code results in double dereferencing when the vector elements a...
I believe that this code results in double dereferencing when the vector elements are accessed Not necessarily. Compilers are pretty smart and should be able to eliminate common subexpressions. They can see that the operator [] doesn't change the 'pointer to the first element', so they have no need make the CPU reloa...
1,771,386
1,771,453
Explain the Need for Mutexes in Locales, Please
Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded applications which use ostringstream frequently. This is apparently due to a mutex 'needed' by the C++ locale machinery. Given my re...
It's really an implementation issue, but std::locale has a static function that retrieves and set the 'global' locale. The global locale is defined to be used in several areas of the standard library which implies that there must be a global locale somewhere. In implementations that support threads it is very likely th...
1,771,518
1,771,593
Ensuring certain private functions can only be called from a locked state
Say I have a class A: class A { public: A(); void fetch_data() { return 1; } void write_x_data() { // lock this instance of A private_function1_which_assumes_locked(); private_function2_which_assumes_locked(); // unlock this instance of A } void write_y_data() { // lock this ins...
You could use a locker class, and require one to exist in order to call the private functions: class A { public: void write() { Lock l(this); write(l); } private: void lock(); void unlock(); void write(const Lock &); class Lock { public: explicit Lock(A *a) ...
1,771,692
1,772,605
When does template instantiation bloat matter in practice?
It seems that in C++ and D, languages which are statically compiled and in which template metaprogramming is a popular technique, there is a decent amount of concern about template instantiation bloat. It seems to me like mostly a theoretical concern, except on very resource-constrained embedded systems. Outside of ...
There's little problem in C++, because the amount of template stuff you can do in C++ is limited by their complexity. In D however ... before CTFE (compile-time function evaluation) existed, we had to use templates for string processing. This is also the reason big mangled symbols are compressed in DMD - the strings us...
1,771,980
1,772,915
Porting linux socket application to windows usins MsDev
Is there openly available headers which can be used to compile linux socket application (using socket/udp/ip headers). they should define structures like sa_family_t,in_port_t Mandatory is to use Msdev and not cygwin/gcc or mingw compiler.
As far as I know, there is no easy way to do this. Windows provides an entirely different set of system calls than linux, as well as a different method for handling sockets.
1,772,395
1,772,474
C++ bool array as bitfield?
let's say i need to store 8 bools in a struct, but i want to use for them only 1 byte together, then i could do something like this: struct myStruct { bool b1:1; bool b2:1; bool b3:1; bool b4:1; bool b5:1; bool b6:1; bool b7:1; bool b8:1; }; and with this i could do things like myStruc...
I would recommend using a std::bitset That way you could simply declare: std::bitset<8> asdf; and use it with []. asdf[0] = true; asdf[3] = false;
1,772,400
1,772,492
boost split compile issue
I have the following code snippet. I am compiling using the sun studio 12 compiler and have tried boost 1.33 and 1.39 #include <boost/algorithm/string.hpp> #include <string> #include <vector> using namespace boost; using namespace std; int main(int argc, char* argv[]) { string exbyte = "0x2430"; string exby...
Other than the missing semi-colon after return 0, which I assume is an unrelated typo, your code compiles fine for me, using gcc 4.3.2. According to the documentation for boost::split, you're using the function correctly, so I don't think this is a coding error. Are you sure you have boost installed correctly? Edit: ...
1,772,485
1,772,504
Printf and hex values
So, I have a value of type __be16 (2 bytes). In hex, the value is represented as 0x0800 or 2048 in decimal. (16^2 * 8) So, when I printf this; I do this: printf("%04X", value); //__be16 value; //Print a hex value of at least 4 characters, no padding. output: 0008 printf("%i", value); //Print a...
My guess is that value is 8. :-) Are you on a little endian machine, such as x86? I'm going to guess that by be16 you mean that the value is big endian and you need to swap the bytes.
1,772,672
1,772,724
Are there compiler flags to get malloc to return pointers above the 4G limit for 64bit testing (various platforms)?
I need to test code ported from 32bit to 64bit where pointers are cast around as integer handles, and I have to make sure that the correct sized types are used on 64 bit platforms. Are there any flags for various compilers, or even flags at runtime which will ensure that malloc returns pointer values greater than the 3...
One technique I have used in the past is to allocate enough memory at startup that all the address space below the 4GB limit is used up. While this technique does rely on malloc first using the lower parts of the address space, this was true on all the platforms I work on (Linux, Solaris and Windows). Because of how L...
1,772,679
1,773,163
Anybody tried to compile Go on Windows?, It appears to now support generating PE Format binaries
http://code.google.com/r/hectorchu-go-windows/source/list If you could compile it successfully, I like to know the procedures of how to.
Assuming you are using Hector's source tree: Install MinGW and MSYS, along with MSYS Bison and any other tools you think you'll find useful (vim, etc). Install ed from the GNUWin32 project. Install Python and Mercurial. Clone the [hectorchu-go-windows mercurial repository](https://hectorchu-go-windows.googlecode.com/h...
1,772,838
1,772,891
invalid initialization of non-const reference of type ‘int&' from a temporary of type 'MyClass<int>::iterator*'
I'm getting the following error from g++ while trying to add iterator support for my linked list class. LinkedList.hpp: In member function ‘Type& exscape::LinkedList<Type>::iterator::operator*() [with Type = int]’: tests.cpp:51: instantiated from here LinkedList.hpp:412: error: invalid initialization of non-cons...
you're returning a reference on a temporary object : this - p->data (I emphasized the typo) computes a pointer interval, and the result of the operation is a temporary rvalue: you can't take a reference from it. Just remove the typo: this->p->data;
1,773,079
1,773,097
Segmentation Fault With Char Array and Pointer in C on Linux
So I have the following program: int main(){ char* one = "computer"; char two[] = "another"; two[1]='b'; one[1]='b'; return 0; } It segfaults on the line "one[1]='b'" which makes sense because the memory that the pointer "one" points to must be in read only memory. However, the question is why doesn't the li...
one points directly to the string located in a read-only page. On the other hand, two is an array allocated on the stack and is initialized with some constant data. At run time, the string in the read only section of the executable will be copied to the stack. What you are modifying is the copy of that string on the st...
1,773,381
1,961,610
What is the "Shell Namespace" way to create a new folder?
Obviously this is trivial to do with win32 api - CreateDirectory(). But I'm trying to host an IShellView, and would like to do this the most shell-oriented way. I would have thought that there would be a createobject or createfolder or some such from an IShellFolder. But neither IShellView nor IShellFolder nor even ...
Shell folders usually implement the IStorage interface, so this is pretty simple. For example, the following creates a folder named "abcd" on the desktop: CComPtr<IShellFolder> pDesktop; HRESULT hr = SHGetDesktopFolder(&pDesktop); if (FAILED(hr)) return; CComQIPtr<IStorage> pStorage(pDesktop); if (!pStorage) ...
1,773,426
1,774,512
convert a list of structs from c# to c++
I have the following c# code static void Main(string[] args) { List<Results> votes = new List<Results>(); } public struct Results { public int Vote1; public int Vote2; public int Vote3; public Candidate precinctCandidate; }; public class Candidate { pu...
Here is a direct translation of your code to C++/CLI: using namespace System; using namespace System::Collections::Generic; public ref class Candidate { public: Candidate() { } property String^ Name { String^ get() { return this->name; } void set(String^ value) { this->name = valu...
1,773,470
1,773,488
What is the Code Definition Window in Visual C++ 2008 Express?
I am working on the Sphere Online Judge problems (OK I am only on my 2nd lol) and using VC++ 2008 express and have just noticed the "code definition window". What exactly does this thing do? Is it any use to a beginner like me?
The code definition window gives you additional context for the code you have the cursor over. For example if you have the cursor over Cat in the following code: Cat c; Then it will display the definition of the Cat class in the code definition window. If you have the following code: c.meow(); And you have the cursor...
1,773,526
1,773,620
In-place C++ set intersection
The standard way of intersecting two sets in C++ is to do the following: std::set<int> set_1; // With some elements std::set<int> set_2; // With some other elements std::set<int> the_intersection; // Destination of intersect std::set_intersection(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), std::inserter(...
I think I've got it: std::set<int>::iterator it1 = set_1.begin(); std::set<int>::iterator it2 = set_2.begin(); while ( (it1 != set_1.end()) && (it2 != set_2.end()) ) { if (*it1 < *it2) { set_1.erase(it1++); } else if (*it2 < *it1) { ++it2; } else { // *it1 == *it2 ++it1; ...
1,773,757
1,773,966
Checking for list membership using the STL and a unary function adapted functor
I've attempted to write a brief utility functor that takes two std::pair items and tests for their equality, but disregarding the ordering of the elements. Additionally (and this is where I run into trouble) I've written a function to take a container of those std::pair items and test for membership of a given pair arg...
There are a couple of issues with your EqualPairs template. It derives from binary_function but isn't actually a binary_function because operator() only takes one argument. You can (and should) make operator() const as it doesn't modify the EqualPairs object. I think that you can simplify it somewhat. template<class T>...
1,773,897
1,773,918
Why is argc an 'int' (rather than an 'unsigned int')?
Why is the command line arguments count variable (traditionally argc) an int instead of an unsigned int? Is there a technical reason for this? I've always just ignored it when trying rid of all my signed unsigned comparison warnings, but never understood why it is the way that it is.
The fact that the original C language was such that by default any variable or argument was defined as type int, is probably another factor. In other words you could have: main(argc, char* argv[]); /* see remark below... */ rather than int main(int argc, char *argv[]); Edit: effectively, as Aaron reminded us, the...
1,774,129
1,774,140
How can we find the process ID of a running Windows Service?
I'm looking for a good way to find the process ID of a particular Windows Service. In particular, I need to find the pid of the default "WebClient" service that ships with Windows. It's hosted as a "local service" within a svchost.exe process. I see that when I use netstat to see what processes are using what ports it ...
QueryServiceStatusEx returns a SERVICE_STATUS_PROCESS, which contains the process identifier for the process under which the service is running. You can use OpenService to obtain a handle to a service from its name.
1,774,187
1,774,195
Is the order of initialization guaranteed by the standard?
In the following code snippet d1's initializer is passed d2 which has not been constructed yet (correct?), so is the d.j in D's copy constructor an uninitialized memory access? struct D { int j; D(const D& d) { j = d.j; } D(int i) { j = i; } }; struct A { D d1, d2; A() : d2(2), d1(d2) {} }; Which...
I don't have the standard handy right now so I can't quote the section, but structure or class member initialisation always happens in declared order. The order in which members are mentioned in the constructor initialiser list is not relevant. Gcc has a warning -Wreorder that warns when the order is different: ...
1,774,222
1,774,228
Taking screenshot of a specific window - C++ / Qt
In Qt, how do I take a screenshot of a specific window (i.e. suppose I had Notepad up and I wanted to take a screenshot of the window titled "Untitled - Notepad")? In their screenshot example code, they show how to take a screenshot of the entire desktop: originalPixmap = QPixmap::grabWindow(QApplication::desktop()->wi...
I'm pretty sure that's platform-specific. winIds are HWNDs on Windows, so you could call FindWindow(NULL, "Untitled - Notepad") in the example you gave.
1,774,661
1,774,672
create singleton class that has constructor which accepts arguments that are evaluated runtime
I want to have singleton class that its object is not statically created. having the following code, when I call ChromosomePool::createPool() I get the following error message : --> ChromosomePool.h:50: undefined reference to `myga::ChromosomePool::pool' <-- Can anyone please tell me how can I solve the problem ? class...
Static members have to be defined, you are only declaring pool as existing somewhere. Put this in the corresponding source file: ChromosomePool* ChromosomePool::pool = 0; Here is the entry in C++ FAQ lite for the subject.
1,774,685
1,774,695
boost linker errors -regular expressions - c++
hi am trying to compile a simple program in boost library but i keep getting linker errors #include <iostream> #include <string> #include <boost\regex.hpp> // Boost.Regex lib using namespace std; int main( ) { std::string s, sre; boost::regex re; while(true) { cout << "Expression: "; cin ...
If you get the Boost libraries from the official source distribution, make sure you build the binaries using bjam (a lot of the boost libraries are header-only and don't require you to do this; the regex library needs to be built). It looks like the libraries are distributed with the devpack release, so this shouldn't...
1,774,882
1,775,109
C++ instantiate templates in loop
I have have a factory class, which needs to instantiate several templates with consecutive template parameters which are simple integers. How can I instantiate such template functions without unrolling the entire loop? The only thing that can think of is using boost pre-processor. Can you recommend something else, wh...
Template parameters have to be compile-time constant. Currently no compiler considers a loop counter variable to be a constant, even after it is unrolled. This is probably because the constness has to be known during template instantation, which happens far before loop unrolling. But it is possible to construct a "recu...
1,774,911
1,775,092
How to design a C++ API for binary compatible extensibility
I am designing an API for a C++ library which will be distributed in a dll / shared object. The library contains polymorhic classes with virtual functions. I am concerned that if I expose these virtual functions on the DLL API, I cut myself from the possibility of extending the same classes with more virtual functions ...
Several months ago I wrote an article called "Binary Compatibility of Shared Libraries Implemented in C++ on GNU/Linux Systems" [pdf]. While concepts are similar on Windows system, I'm sure they're not exactly the same. But having read the article you can get a notion on what's going on at C++ binary level that has an...
1,774,920
1,775,035
Can I use a shared library compiled on Ubuntu on a Redhat Linux machine?
I have compiled a shared library on my Ubuntu 9.10 desktop. I want to send the shared lib to a co-developer who has a Red Hat Enterprise 5 box. Can he use my shared lib on his machine?
First point: all of the answers regarding compiler version seem misguided. What's important are the linkages (and the architecture, of course). If you copy the .so file over to the start system (into its own /usr/local/* or /opt/* directory, for example) then try to run the intended executable using an LD_PRELOAD envi...
1,775,216
1,775,231
SIGINT handling and getline
I wrote this simple program: void sig_ha(int signum) { cout<<"received SIGINT\n"; } int main() { string name; struct sigaction newact, old; newact.sa_handler = sig_ha; sigemptyset(&newact.sa_mask); newact.sa_flags = 0; sigaction(SIGINT,&newact,&old); for (int i=0;i<5;i++) { cout<<"Enter text: "; ...
Try adding the following immediately before your cout statement: cin.clear(); // Clear flags cin.ignore(); // Ignore next input (= Ctr+C)
1,775,573
1,775,590
C++ programing error
I am new to C++ programming. So I was trying my luck executing some small programs. I am working on HP-UX which has a compiler whose executable is named aCC. I am trying to execute a small program #include <iostream.h> using namespace std; class myclass { public: int i, j, k; }; int main() { myclass a, b; ...
Which version of aCC are you using? Older versions used a pre-standard STL implemenntation that put everything in the global namespace (i.e. didn't use the std namespace) You might also need to use the -AA option when compiling. This tells the compiler to use the newer 2.x version of HP's STL library. >aCC -AA temp....
1,775,737
1,775,839
How can I open a C++ or Java project S60 5th Edition SDK 1.0 with Netbeans
I installed S60 5th Edition SDK 1.0 but I can't open project on netbeans? How can this be done?
for a java project, you need to install the Mobility plugin. go to the Tools/Plugins menu, and select Mobility in the Available plugins tab. once you installed the plugin, you need to add the S60 SDK as a platform: go to the Tools/Java Platform menu and click on the Add platform button. In the dialog window which open...
1,775,784
1,775,795
Strange class behaviour when used inside a Qt app
I've a simple class with these, also simple, constructors: audio::audio() { channels = NULL; nChannels = 0; } audio::audio(const char* filename) { audio(); getFromFile(filename); } (Before it was audio():channels(NULL), nChannles(0), loaded(false){..., I'll say later why this changed...). The functi...
The problem is in the audio::audio(const char* filename) constructor. The first statement is audio(); which I believe you are trying to call the default constructor. However, C++ doesn't allow one ctor to call another one. So you have uninitialized pointers. If you want to do something like this, write a private metho...
1,775,822
1,776,178
Out of memory on _beginthreadex
I currently debug a multi threaded application, which runs without errors until some functions where called about 2000 times. After that the application stops responding, which I could track down to _beginthreadex failing with an out of memory error. When examining the Application in ProcessExplorer I can see a grow...
The virtual memory available to a process is 2Gb of the 4Gb address space. Each Thread reserves about 1Mb of virtual memory space by default for its stack space. win32 applications therefore have a limit of about 2000 live threads before virtual memory becomes exhausted. Virtual memory is the memory that applications g...
1,776,174
1,776,313
C++ new standard, technologies and more
I'm developing in C++ mainly. i used to develop using VS 2005 with libraries like MFC , sometimes using COM. only on WIN platform. as i took a break from programming for a year, I want to be able now to get acquainted with all the new features and technologies being used today with C++. Is MFC still worth something tod...
There's a lot of MFC out there, and it isn't going away any time soon. It's still a quite viable way to get stuff done, and it's going to keep working for the foreseeable future. That said, it's no longer the preferred framework from Microsoft, and third-party support (libraries and such) is dying off. If you are start...
1,776,291
1,776,301
Function names in C++: Capitalize or not?
What's the convention for naming functions in C++? I come from the Java environment so I usually name something like: myFunction(...) { } I've seen mixed code in C++, myFunction(....) MyFunction(....) Myfunction(....) What's the correct way? Also, is it the same for a class method as well as a non-class method?
There isn't a 'correct way'. They're all syntactically correct, though there are some conventions. You could follow the Google style guide, although there are others out there. From said guide: Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExciting...
1,776,372
1,781,820
Custom painting QMainWindow title bar
Does anybody know how can I customize title bar of a main window in QT? I would like to make some custom painting over the "normal" drawing. The QT version I'm interested in is 4.5 or 4.6 (beta)
Actually, the title bar is a part of what the "window manager" adds. This could be Windows, OS X or whatever you are running in your X11 environment. Either way, you need to remove the bar and replace it with one of your own. To do this, use the Qt::WindowFlags (http://doc.qt.digia.com/4.5/qt.html#WindowType-enum) to m...
1,776,384
1,783,038
How can I add widgets to title bars in QMainWindow?
Is any posibility to add widgets in titlebar of QMainWindow? I try to avoid "emulate" a title bar by making a custom widget for that and hiding the default title bar (from Qt::WindowFlags). I am using QT 4.5 or 4.6 beta.
You cannot. What you can do is to create a completely custom window by hinting that you don't want a title bar using a Qt::WindowFlag. Notice - these flags are hints and not settings. Then you can create your own title bar and add whatever you like to it. Also, notice, this will make your application harder to move bet...
1,776,399
1,776,421
What are the trade-offs between procedurally copying a file versus using ShellExecute and cp?
There are at least two methods for copying a file in C/C++: procedurally and using ShellExecute. I can post an explanation of each if needed but I'm going to assume that these methods are known. Is there an advantage to using one method over the other?
Procedurally will give you better error checking/reporting and will work cross-platform -- ShellExecute is Windows API only. You could also use a third-party filesystem library to make the task less annoying -- boost::filesystem is a good choice.
1,776,491
1,776,498
Question on C++ Timers
I am currently working on a project that will act like a Online selling website such as Amazon, or Ebay in a very small scale. I was wondering if anyone could point me in the right direction on how to use Timers for C++. Learning Socket Programming at the moment, and was trying to incorporate the timer for the auction ...
You mean like timer_create? How are you handling your sockets? Threads or select? If the latter (or something like select), timer_create will be a natural fit.
1,776,634
1,778,461
Design and Readbility
I am working on a project written in C++ which involves modification of existing code. The code uses object oriented principles(design patterns) heavily and also complicated stuff like smart pointers. While trying to understand the code using gdb,I had to be very careful about the various polymorphic functions being ca...
gdb is not a tool for understanding code, it is a low-level debugging tool. Especially when using C++ as a higher level language on a larger project, it's not going to be easy to get the big picture from stepping through code in a debugger. If you consider smart pointers and design patterns to be 'complicated stuff' th...
1,776,636
1,776,782
C++ overloading operator= in template
Hi all I'm having trouble with C++ template operator= What I'm trying to do: I'm working on a graph algorithm project using cuda and we have several different formats for benchmarking graphs. Also, I'm not entirely sure what type we'll end up using for the individual elements of a graph. My goal is to have a templated...
The problem is you're returning by value (correctly) but trying to bind that temporary object to a non-const reference (for the op= parameter). You can't do this. The solution is to change things around, which can result in non-idiomatic code; use an auto_ptr_ref-like construct, which gets around this in a fairly bad-...
1,776,641
1,776,659
How do I apply the DRY principle to iterators in C++? (iterator, const_iterator, reverse_iterator, const_reverse_iterator)
OK, so I have two (completely unrelated, different project) classes using iterators now. One has iterator and reverse_iterator working as intended, and the other, current one has iterator and a semi-broken const_iterator (specifically, because const_iterator derives from iterator, the code LinkedList<int>::iterator i =...
Sometimes, blanket application of the so-called DRY rule (Don't Repeat Yourself, for those who aren't familiar) is not the best approach. Especially if you're new to the language (C++ and iterators) and OOP itself (methodology), there's little benefit in trying to minimise the amount of code you need to write right now...
1,776,961
1,784,986
Finite State Machine program
I am tasked with creating a small program that can read in the definition of a FSM from input, read some strings from input and determine if those strings are accepted by the FSM based on the definition. I need to write this in either C, C++ or Java. I've scoured the net for ideas on how to get started, but the best ...
First, get a list of all the states (N of them), and a list of all the symbols (M of them). Then there are 2 ways to go, interpretation or code-generation: Interpretation. Make an NxM matrix, where each element of the matrix is filled in with the corresponding destination state number, or -1 if there is none. Then jus...
1,776,971
1,776,982
How should I handle Inconsistent Objects in C++?
Say, I want to create a File class class File{ public: File(const char *file){ openFile(file); } ~File(); isEmpty(); }; openFile checks if the file exists or if the contents of the file are valid or not. File *file = new File("filepath"); if(file) file->isEmpt...
Your constructor should throw an exception in the case that the file couldn't be opened. File::File( const char* pPath ) { if ( !openFile( pPath ) ) throw FileNotFound( pPath ); }
1,776,993
1,777,052
C++ collection of abstract base classes
how can I create STL collection of classes which implement abstract base class using the base class as collection value, without using pointers? is there something in Boost that allows me to implement it? The collection specifically is map. Thanks
You cannot avoid pointers completely. You must store pointers in the collection if you want to avoid Object slicing. Boost has a container that hides the pointers pretty well: ptr_map
1,777,060
1,777,064
What Linux Full Text Indexing Tool Has A Good C++ API?
I'm looking to add full text indexing to a Linux desktop application written in C++. I am thinking that the easiest way to do this would be to call an existing library or utility. This article reviews various open source utilities available for the Gnome and KDE desktops; metatracker, recoll and stigi are all written i...
I used CLucene, which you mentioned (and also Lucene.NET), and found it to be pretty good.
1,777,308
1,777,346
What does this code-snippet do?
Question: Given the following code snippet: bool foo(int n) { for(int i=3;i<sqrt(n)+0.5;i+=2) { if((n%i)==0){ return false; } } return true; } Can you figure out what is the purpose of the function foo ? Well,On first look it may seems that foo is checking for prime number...
It looks like a prime number checker that doesn't deal with even numbers or one, i.e. it assumes that you've already discarded even numbers and one. The numbers for which it returns true are primes, or some non-primes that consist of powers of two multiplied by at most one other prime. The non-primes that it returns tr...
1,777,367
1,777,626
Display a month not as the number 1
I am having trouble trying to figure out how i would display a month without having to display "January" like in my switch - if i try to just oputput it i get a number 1 Do i need to create memory for the date priceDate; private member? than copy in my copy constructor? sorry about formatting. i had to move stuff over ...
Enums are just numbers. If you want an enum value to correspond with a string, then you need to create a mapping of some sorts, for example: const char * asString(Month month) { static const char * cMonths[] = { "January", "February", "March", "April", "May", "June", ...
1,777,486
1,777,677
Function Pointers in Objective C
Quick question. Does anyone know how to get the function pointer of an objective c method? I can declare a C++ method as a function pointer, but this is a callback method so that C++ method would need to be part of the class SO THAT IT CAN ACCESS THE INSTANCE FIELDS. I don't know how to make a C++ method part of an obj...
Typically, you need two pieces of information to call back into Objective-C; the method to be invoked and the object to invoke it upon. Neither just a selector or just the IMP -- the instanceMethodForSelector: result -- will be enough information. Most callback APIs provide a context pointer that is treated as an op...
1,777,553
6,755,651
G++ Compilers for MonoDevelop
How do you setup a G++ compiler for MonoDevelop? On both OS X and Windows Vista the default install complains about "Compiler Not Found: g++". Is MonoDevelop not a good cross platform IDE for C++ development (since it is a C#/Java IDE). Thanks SO!
I would say it is not. C# and C++ are 2 different worlds. My suggestion: If you want to write xplatform apps in C++, get familiar with either wxWidgets or QT. wxWidgets has a more liberal license though and does not need a metacompiler. In the newest release it makes also use of the STL, if the compiler supports it....
1,777,639
1,777,647
How to test a byte against a hex value?
I want to test if the byte I read from a data file is 0xEE, what should I do? I tried if (aChar == 0xEE) but doesn't seems working.
When reading a signed char, the value will never be 0xEE. IE: #include <stdio.h> int main() { char c = 0xEE; // assumes your implementation defines char as signed char // c is now -18 if (c == 0xEE) { printf("Char c is 0xEE"); } else { printf("Char c is NOT 0xEE"); } ...
1,777,717
1,796,246
Is this a fine std::auto_ptr<> use case?
Please suppose I have a function that accepts a pointer as a parameter. This function can throw an exception, as it uses std::vector<>::push_back() to manage the lifecycle of this pointer. If I declare it like this: void manage(T *ptr); and call it like this: manage(new T()); if it throws an exception pushing the poi...
I think enough discussion has been generated to warrant yet another answer. Firstly, to answer the actual question, yes, it is absolutely appropriate (and even necessary!) to pass an argument by smart pointer when ownership transfer occurs. Passing by a smart pointer is a common idiom to accomplish that. void manage(st...
1,777,730
1,777,761
Learning c++ from a C# background
I want to learn c++ as I will be working on image recognition, etc. I have a few years solid experience in C# and I have made stuff with C# so I'm not lacking experience. What is a good book which will help me make the transition (I will still be doing C# as it is my main skill)? Also, would you agree that to be good a...
Also, would you agree that to be good at C++, a lot of experience and being proficient in C# will help? As C++ is harder... Yes I agree with that. A lot of experience in development in any language helps in my opinion. With experience comes appreciation of best practices. Those practices may be different, but...
1,777,752
1,777,817
Python importing & using cdll (with a linux .so file)
After one of my last questions about python&c++ integration i was told to use dlls at windows. (Previous question) That worked ok doing: cl /LD A.cpp B.cpp C.pp in windows enviroment, after setting the include path for boost, cryptopp sources and cryptopp libraries. Now i'm tryting to do the same in linux, creating a ....
C++ compiler mangles names of functions. To do what you are trying to do you must have the declaration prototype inside extern "C" {...} it's hard to tell from your samples what exactly you have in a source file. As someone already mentioned, use nm utility to see what objects that are in your shared object. Do not ...
1,777,855
1,777,860
Trying to visualize points on a graph: how can I make C++ output this?
I am trying to create a simple visualization of what my code does. I am making a Poisson-Disk-Distribution class to generate a set of random points in a bounded rectangular region. Basically, what it does is it randomly generates a specified number of points in the bounded region and makes sure that each point is at le...
Assuming your data structure is a list of (x,y) pairs, a simple printing function could be: for each row for each column in current row if the pair (col,row) exists in the list of (x,y) points print "x" else print "-" print newline Since this has at least three nested lo...
1,778,042
7,388,714
Pop3 help for a C++ implementation!
Alright, so this is absolutely killing me... If anyone could help me, I would be the happiest man on the face of the earth... So, I need to create a C++ email client for a project at school, and I've been using the POCO open source C++ library, and I've been fine for working with email servers that do not need SSL auth...
As the error states fatal error C1083: Cannot open include file: 'Poco/Crypto/X509Certificate.h' This means it cant find the file, that is the only problem!!!
1,778,111
1,778,118
What's the differences between .dll , .lib, .h files?
Why in a project should I include some *.lib, .h or some other files? And what are these things used for?
.h: header file, its a source file containing declarations (as opposed to .cpp, .cxx, etc. containing implementations), .lib: static library may contain code or just links to a dynamic library. Either way it's compiled code that you link with your program. The static library is included in your .exe at link time. .dll...
1,778,191
1,778,200
Base Class Pointer to Hold Boost Enum
Currently, I am using a type-safe enum class from Boost Vault : Which Typesafe Enum in C++ Are You Using? I found it is difficult to have a parent class pointer to refer to all enum class, due to Boost::enum is a template class : boost::detail::enum_base<T> I am using void fun(const boost::any& any), to accept any enum...
If the access is not possible through the base class, use function templates: template<class TE> // should be a boost enum void fun(TE& en) { for (TE::const_iterator it = en.begin(); it != en.end(); ++it) { /* ... */ } } As for a common base pointer: You can't use one the way the boost enum is defi...
1,778,209
1,778,213
suggest some online compiler for c/c++
I am developing a website for which I need an online C/C++ compiler for testing code online. Is there any possible and feasible solution for this? I need this compiler so that students can test their code online.
Codepad For others languages too!
1,778,218
1,826,522
Parser for 32-bit and 64-bit Mach-O binary/executable formats in C++
I'm looking for a C++ library that can parse 32-bit and 64-bit Mach-O binary format. I don't need anything fancy, just a disassembly and splitting the file into its sections, so no decompilation, name demangling and so on. I know I can either rip open any existing disassembler or craft my own binary parsers using the f...
You can start with the open-source class-dump tool (http://www.codethecode.com/projects/class-dump/). It can read both 32 and 64 bits Mach-o binaries, and is known to have a decent parser.
1,778,245
1,778,258
No Matching Function for Call to
In my object ' handler ' I have the following code: Product tempProduct; // temporary Product storage variable LINE481 tempProduct.setHandler(this); Within my Product.h: #include <string> #include <qtimer.h> #include "HandleTCPClient.h" #ifndef PRODUCT_H #define PRODUCT_H class Handler; //Define ourselves a pro...
You probably want to declare your setHandler function like this: void Product::setHandler(Handler *h) Also, inside the Product class, declare handler like this: Handler *handler; It looks like you might be more familiar with a language such as Java or Python that doesn't have an explicit pointer syntax. In C++, you m...