|
|
Up |
|
|
  |
Author: coolrahulcoolrahul
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
|
|
  |
Author: KannanKannan
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
|
| |
|
| |
no comments
|
|
  |
Author: bashill.zhubashill.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
|
|
  |
Author: lukasz.lewlukasz.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
|
| |
|
no comments
|
|
  |
Author: mojumbomojumbo
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 |
|
  |
Author: zerozero
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 |
|
  |
|
|
  |
Author: korben dallaskorben 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 |
|
  |
Author: mail.dpantmail.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
|
|
  |
|
|
  |
Author: David AbrahamsDavid 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
|
|
|
|
|
|
|