Forum: C++ Nov 21st, 2008 |
| Replies: 5 Views: 1,999 > what is the relation between a socket and a port.
> I mean a socket is a special kind of file descriptor
> when i use file descriptors i don't use ports
> why we have to use ports when we use a... |
Forum: C++ Nov 20th, 2008 |
| Replies: 5 Views: 1,999 > i read somewhere that sockets are full duplex, so initially i tried to build an architecture like this:
a socket is *one* end of a two-way communications link.
a BSD socket maintains a separate... |
Forum: C++ Nov 18th, 2008 |
| Replies: 1 Views: 426 > can u pass template class objects as parameters to friend functions of the same class??
obviously, you can. but you need to let the compiler know that they are templates.
#include <iostream>
... |
Forum: C++ Nov 17th, 2008 |
| Replies: 5 Views: 1,999 First, is this the "best" way to tackle the chat problem?
no. it is unlikely that someone would want to set up a chat between two processes on the same machine, sharing stdin and stdout between... |
Forum: C++ Nov 17th, 2008 |
| Replies: 3 Views: 697 you need to enable RTTI. (use compiler switches for this.)
either you have turned it off by using the switch /GR-
or you are using a fairly old version of the microsoft compiler.
turn it on with... |
Forum: C++ Nov 16th, 2008 |
| Replies: 1 Views: 352 read the following pages and you should be ok:
http://www.relisoft.com/science/CrcMath.html
http://www.relisoft.com/science/CrcNaive.html... |
Forum: C++ Nov 16th, 2008 |
| Replies: 2 Views: 1,638 > man mmap <Enter>
at the command prompt on your system. it should give you all the information that you require.you would see something like this:... |
Forum: C++ Nov 13th, 2008 |
| Replies: 3 Views: 607 > declare it as private and just leave an empty implementation?
ideally, declare it as private and do not define it.
> Is this common/useful?
useful, yes. common, not all that much.
if there is... |
Forum: C++ Nov 13th, 2008 |
| Replies: 2 Views: 4,055 > It keeps saying:
> Failed to connect with the server : Bad file descriptor
that says all that needs to be said, doesn't it?
int websock; // websock is an uninitialized int
... |
Forum: C++ Nov 7th, 2008 |
| Replies: 7 Views: 788 struct base
{
virtual std::ostream& write( std::ostream& stm ) const = 0 ;
// ...
};
inline std::ostream& operator<< ( std::ostream& stm, const base& object )
{
return object.write(... |
Forum: C++ Nov 4th, 2008 |
| Replies: 3 Views: 446 this is broken when C is a const container.
c.begin() and c.end() returns objects of type C::const_iterator.
in C++98 you would have to do something like
template < typename CNTR > struct... |
Forum: C++ Nov 4th, 2008 |
| Replies: 1 Views: 351 have a look at the standard header <utility>. it defines std::pair and std::make_pair.
template <typename First, typename Second>
struct Pair
{
First f;
Second s;
Pair( const First&... |
Forum: C++ Oct 30th, 2008 |
| Replies: 1 Views: 442 bulk rename of all the .wav files in one go and updating the text in all the .phr files at another time can leave you in a messy state in the event of a crash (you would have to restart all over... |
Forum: C++ Sep 28th, 2008 |
| Replies: 6 Views: 1,196 the general knapsack problem and the subset sum problem are NP-hard, but not NP-incomplete. so there are no polynomial-time algorithms. but it is one of the easy NP-complete problems to solve.
it... |
Forum: C++ Sep 28th, 2008 |
| Replies: 11 Views: 1,128 this is nothing specific to constructors or passing parameters to functions.
it is just the application of the C++ rules for resolving a call to an overloaded function.
#include <iostream>
void... |
Forum: C++ Sep 26th, 2008 |
| Replies: 2 Views: 388 > #pragma - what does it mean
to understand what #pragma is see: http://msdn.microsoft.com/en-us/library/d9x1s805(vs.71).aspx
for the specific #pragma directives that are in your code, refer to... |
Forum: C++ Sep 26th, 2008 |
| Replies: 2 Views: 441 have each of the two stacks to store a reference to a std::deque.
initialize them to refer to the same std::deque.
write a wrapper class to hold the two stacks.
template< typename T > struct... |
Forum: C++ Sep 26th, 2008 |
| Replies: 9 Views: 719 writing a convert function (with construction and destruction of a stringstream each time it is called) would give more maintainable code. even in this case, the performance seems to be acceptable:... |
Forum: C++ Sep 26th, 2008 |
| Replies: 9 Views: 719 only because the language the OP is using ( MessageBox::Show ) is C++/CLI (not ISO C++).
and purely managed will not give anywhere near native performance. |
Forum: C++ Sep 26th, 2008 |
| Replies: 7 Views: 573 in adition, change int size = 100; to const int size = 100;
size of an array must be a constant known at compile time. |
Forum: C++ Sep 26th, 2008 |
| Replies: 9 Views: 719 > What I look for now is a fast way to convert from double to char*
> I have a problem to find this conversion.
a. compile C++ source to generate native code, not IL that is interpreted at... |
Forum: C++ Sep 17th, 2008 |
| Replies: 4 Views: 1,355 consider using the std::tr1 polymorphic function wrappers. this would allow using free functions, member functions and function objects in a polymorphic way.
if your compiler does not ship with... |
Forum: C++ Sep 17th, 2008 |
| Replies: 7 Views: 984 > But I still find it ackward, that there are no possibility to do it.
> I can handle special cases when, I have different INPARS as long as the method is void.
> But it's not possible to do it... |
Forum: C++ Sep 17th, 2008 |
| Replies: 2 Views: 958 a std::tr1::shared_ptr cannot correctly hold a pointer to a dynamically allocated array. AFAIK, there is no such smart pointer in tr1.
you could use boost::shared_array (tr2) instead.... |
Forum: C++ Sep 16th, 2008 |
| Replies: 14 Views: 1,110 > the self-assignment test does not work well in class hierarchies either,
> even with use of boost::addressof().
it is unlikely that using value semantics on object-oriented types is something... |
Forum: C++ Sep 16th, 2008 |
| Replies: 4 Views: 1,190 perhaps the easiest way is to use the iostream formatted output facilities:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
int main()
{
double a = 2.5632, b =... |
Forum: C++ Sep 16th, 2008 |
| Replies: 8 Views: 710 a little less verbose, and a little more efficient:
#include <vector>
#include <string>
int main ( int argc, char** argv )
{
std::vector< std::string > arguments( argv, argv+argc ) ;
} |
Forum: C++ Sep 16th, 2008 |
| Replies: 14 Views: 1,110 >> The above is common practice, but it is easily broken.
>> Imagine, for example, a class that supports its own operator&() ...
>> The most useful way I've found to do an assignment operator is; ... |
Forum: C++ Sep 16th, 2008 |
| Replies: 9 Views: 1,131 for the predefined streams, it's safe to mix C stdio and C++ iostreams. you can safely use stdin and std::cin in the same program; the C++ Standard guarantees that it will work the way you would... |
Forum: C++ Aug 31st, 2008 |
| Replies: 1 Views: 736 > As a destructor releases memory for an object ...
a destructor does not release memory. it deinitializes an object and after it executes, what is left is uninitialized memory (earlier occupied by... |
Forum: C++ Aug 31st, 2008 |
| Replies: 8 Views: 3,277 > i would like to avoid doing 4 times 2 shift for each char.
> For each char i do 4 shift operations and 4 bitwise AND's, thats 8 bitwise operations.
you can reduce it to just 4 AND operations... |
Forum: C++ Aug 29th, 2008 |
| Replies: 7 Views: 628 also have a look at codeville http://codeville.org/
it is one one of the easiest to use. |
Forum: C++ Aug 29th, 2008 |
| Replies: 7 Views: 988 you can answer this yourself if you write a small test program and run it. for example:
#include <iostream>
struct A
{
A() { std::cout << "A::default constructor\n" ; }
A( const A& ) {... |
Forum: C++ Aug 28th, 2008 |
| Replies: 3 Views: 515 > Does it make sense to write a virtual method in the templated base class
> in order to force derived classes to have an appropriate addelement() method?
no. the polymorphism provided by... |
Forum: C++ Aug 28th, 2008 |
| Replies: 15 Views: 4,561 measurements for the same snippet (3 each) for the microsoft compilers:
compiler: VC++ 9.0 (Express 2008)
optimizations: /Ox /Ob2 /Oi /Ot /Oy /GT /GL
processor: Intel Pentium M 1.86 GHz
c... |
Forum: C++ Aug 28th, 2008 |
| Replies: 3 Views: 515 if you absolutely need a base class Chart (with virtual functions), a hack would be to overload the AddElement function.
i would prefer using templates for your containers as suggested by Narue in... |
Forum: C++ Aug 27th, 2008 |
| Replies: 15 Views: 4,561 valarrays were introduced with the idea that it might encourage C++ compiler developers for vector processors to implement them as built-in types (the compiler could emit code to optimize the use of... |
Forum: C++ Aug 25th, 2008 |
| Replies: 6 Views: 860 Derived d;
Base *p = reinterpret_cast< Base*>(&d);
> I found that this is also legal--
it will compile.
it will work correctly if and only if the anonymous base class sub-object is at an... |
Forum: C++ Aug 25th, 2008 |
| Replies: 9 Views: 682 any 3-combination of the N-set would consist of numbers at 3 different positions in the array; you could choose positions i,j,k out of these three such that i<j<k holds.
so doesn't the problem... |
Forum: C++ Aug 24th, 2008 |
| Replies: 3 Views: 474 > Could it be because i am entering the string 'key' with spaces?
yes
> how would i fix it?
use std::getline
http://www.cppreference.com/cppstring/getline.html |