comp.lang.c++.moderated
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
September 2008
motuwethfrsasuw
1234567 36
891011121314 37
15161718192021 38
22232425262728 39
2930      40
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.c++.moderated Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  function is virtual in derived class but not base class         


Author: coolrahul
Date: Sep 19, 2008 22:40

I am have a fair understanding of how virtual functions work but I am
not able to fathom how this works:

class a {
public:
void fn() {
cout<<"a::fn\n";
}
};

class b : public a {
public:
virtual void fn() {
cout<<"b::fn\n";
}
};

int main() {
a * p = new b();
p->fn();
return 0;
}
Show full article (0.62Kb)
no comments
  STL list unique elements efficiency         


Author: Kannan
Date: Sep 19, 2008 22:30

Hi,

I have a question about efficiency of some combination of STL
functions. By efficiency I mean faster, memory consumption is not a
problem for my application.

For the list container to create a list with unique elements, is it
more efficient to do a find() if not found then push_back() Or
push_back() anyway then do a sort() followed by unique() ?

Another question, when I am doing a find() on a list container, is
there any efficiency advantage if the list has unique only elements?

Any help appreciated. Thank you for your time.

Thanks,
Kannan

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
  about the interator of map         


Author: bashill.zhu
Date: Sep 19, 2008 22:30

This is the exercise of TC++PL ch6
(*2) Read a sequence of possibly whitespaceseparated
(name,value) pairs, where the name is a
single whitespaceseparated
word and the value is an integer or a floatingpoint
value. Compute
and print the sum and mean for each name and the sum and mean for all
names. Hint: §6.1.8.
Show full article (2.07Kb)
no comments
  Mutual dependence         


Author: lukasz.lew
Date: Sep 19, 2008 22:10

I have two classes representing master and slave. Both come in several
variants:
MasterUnsafe, MasterThreadSafe, ...
SlaveLogging, SlaveIgnore, ...

Now It turns out that they need to call each other's methods. And I
can't afford to have virtualcall
especially when slave is SlaveIgnore and does nothing.
I need to have objects of types of any possible combination like:
MasterUnsafe+SlaveLogging
MasterUnsafe+SlaveIgnore
MasterThreadSafe+SlaveLogging
MasterThreadSafe+SlaveIgnore

I thought that inheritnce can help but I can't get it to work.
I guess I have much to learn :)
Can someone give me some hints?

Lukasz

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
  The memory size of a method?         


Author: mojumbo
Date: Sep 18, 2008 14:28

I am passing around a structure, say:

tsBob
{
int a;
int b;
int bobMethod(bool lb);
};

I would like to make sure the structure is aligned along a 64-bit
boundary (it's being thrown around the system). I assumed it was the
size of a pointer (32-bits) but when I googled & wrote a little driver
(See below) it was only 1 byte. Since I can't believe this does
anyone have an answer?

int main(int argc, char* argv[])
{
tsBob aBob;

cout << "Size of bobMethod is " << sizeof(aBob.bobMethod) << endl;

return 0;
}
Show full article (0.68Kb)
4 Comments
  multiple inheritance confusion         


Author: zero
Date: Sep 18, 2008 13:34

Hi all,

given the following code:

#include

struct Abstract {
virtual void HandleIt() = 0;
virtual void Handle( int ) = 0;
virtual ~Abstract() {}
};

struct A : Abstract {
virtual void HandleIt() {
std::cout << "A::Handle()" << std::endl;
Handle( 1 );
}
virtual void Handle( int ) {
std::cout << "A::Handle( int )" << std::endl;
}
};
Show full article (1.32Kb)
1 Comment
  C++0x stream move-assignment == swap?         


Author: Niels Dekker - no return address
Date: Sep 18, 2008 13:24

The C++ Draft specifies that a "move" is equivalent to a swap, for various
stream types. Why was it chosen that way? Wouldn't it be preferable to have
the rvalue in a "default-constructed" state, after the move?

Quoting the Draft,
www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf
> 27.8.1.8 Assign and swap [ifstream.assign]
> basic_ifstream& operator=(basic_ifstream&& rhs);
> Effects: swap(rhs).

As a consequence, the original resources of a stream aren't freed when an
rvalue is assigned to the stream:

// Does not close the file originally held by fstream1.
ifstream1 = std::move(ifstream2);

Isn't that an issue similar to LWG issue #675, "Move assignment of
containers"?
<www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#675>
Show full article (1.04Kb)
1 Comment
  SFINAE?         


Author: korben dallas
Date: Sep 18, 2008 13:23

Hello

Please, consider the following code sample

template void foo(const T&, char(*)[sizeof(T) - 1] = 0);

int foo(...);

int main()
{
char c;
return foo(c);
}

When I try to compile it with Comeau online, it compiles fine, meaning
that the call gets resolved to 'foo(...)'. I assume that it's SFINAE
that kicks in in this case, preventing the template specialization from
being considered as a candidate function (since the array size in the
second parameter evaluates to zero).

However, if I change the template declaration to

template int foo(const T&, char[sizeof(T) - 1] = 0);

Comeau complains with
Show full article (1.16Kb)
1 Comment
  Factory Design Pattern         


Author: mail.dpant
Date: Sep 18, 2008 13:21

I have written a Factory design Patten in C++. can anybody comment is
it the correct way to do it?

#include "stdafx.h"
#include
using namespace std;

/* Display Driver hierarchy */
class DisplayDriver{
public:
DisplayDriver(){}
virtual void display()=0;
};
Show full article (1.74Kb)
no comments
  Re: Best practices? Free functions vs function objects         


Author: David Abrahams
Date: Sep 17, 2008 14:40

On Sep 14, 3:29 pm, Mathias Gaunard gmail.com> wrote:
> On 14 sep, 19:28, Rune Allnor wrote:
>
>> Hi all.
>
>> What are the guidelines / best practices on choosing between
>> implementing some functionality as a free function or a function
>> object?
>
> A function object can do more.
> 1) It can have state
> 2) It can have multiple overloads

3) It can be compile-time polymorphic (templated function call
operator) and still be passed as an argument to a function such as a
std algorithm. You can't do that with a regular function template.

--
Dave Abrahams
Boostpro Computing
http://boostpro.com
Show full article (0.78Kb)
no comments
1 2 3 4 5 6 7 8 9