http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* WORD TO PDF CONVERTER ! - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aa74516e119018a7?hl=en
* opening jpeg file in c++ - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ee4a622091cbf4cb?hl=en
* Electronics - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/14baa777c3867ffa?hl=en
* dynamic array and constructors - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/24c7ef3e322053f1?hl=en
* allocate memory of derived class - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/87fc908ed9682594?hl=en
* Hardware keys - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/562ab6b30cb4fecc?hl=en
* C/C++ language proposal: Change the 'case expression' from "integral
constant-expression" to "integral expression" - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a6452a6641b1fc5b?hl=en
* const correctness - should C++ prefer const member over non-const? - 2
messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/35cc955f55ea7387?hl=en
* vector<const T(*)> vs. vector<T(*)> - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8dca9788b8075995?hl=en
* solving circular dependencies with class only delcared in .h - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/652550d4b8a6f0f8?hl=en
* a really simple C++ abstraction around pthread_t... - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/44190e3b9ac81a69?hl=en
* dynamically allocate array variable type LPWSTR - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/e158b09860db9247?hl=en
* Insert static array of struct in a vector - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/67f0d0e0bb28dd7a?hl=en
* Singleton and static function - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/dab3d2ac69472a4b?hl=en
==============================================================================
TOPIC: WORD TO PDF CONVERTER !
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aa74516e119018a7?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 5:01 am
From: Kimo1021
Dear all,
that program converts from word to pdf very easy and free
DOWNLOAD HERE FOR FREE
http://www.ziddu.com/download/2418735/Savefromwiordaspdfformat.rar.html
==============================================================================
TOPIC: opening jpeg file in c++
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ee4a622091cbf4cb?hl=en
==============================================================================
== 1 of 4 ==
Date: Fri, Oct 31 2008 5:02 am
From: Lionel B
On Fri, 31 Oct 2008 04:20:45 -0700, mohi wrote:
> hello everyone ,
>
> i am trying to read a jpeg image through c++ but is unable to do so ,
> presently i tried it with code in c as i use something like ;
>
> FILE * fp=fopen("./x.jpg","wb");
> int c;
> do{
> read(fp,&c,sizeof(c));
error: invalid conversion from 'FILE*' to 'int'
Note that read (which is not portable, by the way) takes a file
*descriptor*, not a FILE pointer.
[...]
> or what is the best way to read a binary file such as an image ??
A more C++-like style might be something like:
#include <fstream>
#include <iostream>
std::ifstream fs("./x.jpg", std::ios::in|std::ios::binary);
if (!fs) {
// failed to open file - do something about it
}
char c;
while (fs >> c) { // evaluates to false if read fails (e.g. past EOF)
// do something with c
}
fs.close();
--
Lionel B
== 2 of 4 ==
Date: Fri, Oct 31 2008 7:58 am
From: mohi
On Oct 31, 5:02 pm, Lionel B <m...@privacy.net> wrote:
> On Fri, 31 Oct 2008 04:20:45 -0700, mohi wrote:
> > hello everyone ,
>
> > i am trying to read a jpeg image through c++ but is unable to do so ,
> > presently i tried it with code in c as i use something like ;
>
> > FILE * fp=fopen("./x.jpg","wb");
> > int c;
> > do{
> > read(fp,&c,sizeof(c));
>
> error: invalid conversion from 'FILE*' to 'int'
>
> Note that read (which is not portable, by the way) takes a file
> *descriptor*, not a FILE pointer.
>
> [...]
>
> > or what is the best way to read a binary file such as an image ??
>
> A more C++-like style might be something like:
>
> #include <fstream>
> #include <iostream>
>
> std::ifstream fs("./x.jpg", std::ios::in|std::ios::binary);
> if (!fs) {
> // failed to open file - do something about it--
>
> }
>
> char c;
> while (fs >> c) { // evaluates to false if read fails (e.g. past EOF)
> // do something with c
>
> }
>
> fs.close();
>
> --
> Lionel B
i am really sorry people - i the real code would be like --
FILE * fp=fopen("./x.jpg","rb");
int c;
do{
fread(fp,&c,sizeof(c));
if( c==(int) 0xFF23){
do.....
do....
}
printf("%x",c);
}
while(c!=EOF);
== 3 of 4 ==
Date: Fri, Oct 31 2008 8:04 am
From: mohi
hello everyone ,
i am trying to read a jpeg image through c++ but is unable to do so ,
presently i tried it with code in c as i use something like ;
FILE * fp=fopen("./x.jpg","rb");
int c;
do{
fread(fp,&c,sizeof(c));
if( c==(int) 0xFF23){
do.....
do....
}
printf("%x",c);
}
while(c!=EOF);
but the problem is the if condition never evalutes to true as i know
that according to the jpeg standard there should be market with value
0xFFD8 and others also .....and also the printf() of integer 'c' as
hex is never displayed it just displays a blank ..
what could be wrong ??
or what is the best way to read a binary file such as an image ??
thanks a lot
mohan gupta
== 4 of 4 ==
Date: Fri, Oct 31 2008 8:14 am
From: Juha Nieminen
Lionel B wrote:
> char c;
> while (fs >> c) { // evaluates to false if read fails (e.g. past EOF)
Since he wants to read raw binary input into an int, he can do exactly
that also with C++ streams:
fs.read((char*)&theInt, sizeof(int));
He can check if the reading succeeded with fs.fail().
==============================================================================
TOPIC: Electronics
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/14baa777c3867ffa?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 5:04 am
From: swapu
Electronics is the field of manipulating electrical currents and
voltages using passive and active components that are connected
together to create circuits. Electronic circuits range from a simple
load resistor that converts a current to a voltage, to computer
central-processing units (CPUs) that can contain more than a million
transistors. The following indices and documents provide a basic
reference for understanding electronic components, circuits, and
applications.
http://electronicstopics.blogspot.com/2008/10/welcome-to-world-of-electronics.html
==============================================================================
TOPIC: dynamic array and constructors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/24c7ef3e322053f1?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 5:05 am
From: James Kanze
On Oct 31, 9:42 am, Urs Thuermann <u...@janus.isnogud.escape.de>
wrote:
> I have some old code I've written several years ago that
> doesn't compile with newer versions of GCC. The code
> allocates an array of objects that need to be initialized by
> calling a constructor with one argument:
> class B;
> class A {
> B *b;
> public:
> A(B *p) : b(p) {}
> };
> class B {
> public:
> void foo() {
> // this declaration is ok
> A a(this);
> // the following causes an error with newer GCC:
> // error: ISO C++ forbids initialization in array new
> A *arr = new A[10](this);
> }
> };
> int main()
> {
> B b;
> }
> This worked with g++ until version 3.3.x, but not since 3.4.x.
> The problem is in the expression new A[10](this), since
> according to GCC, initialization in array new is forbidden.
It's always been forbidden.
> How would I initialize the array elements in ISO C++?
std::vector< A > v( 10, this ) ;
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
== 2 of 2 ==
Date: Fri, Oct 31 2008 8:01 am
From: Juha Nieminen
James Kanze wrote:
>> How would I initialize the array elements in ISO C++?
>
> std::vector< A > v( 10, this ) ;
That is, of course, the best and safest way of doing it.
OTOH, it might be interesting to know how std::vector does this.
(After all, std::vector *does* allocate space for a certain amount of
elements without needing a default constructor for those elements.) It
goes something like this:
// Requires #include <memory>
A* array = std::allocator<A>().allocate(10);
for(int i = 0; i < 10; ++i)
new(array+i) A(this);
Of course I'm not recommending you to do it like this. Use std::vector
instead.
==============================================================================
TOPIC: allocate memory of derived class
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/87fc908ed9682594?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Oct 31 2008 5:22 am
From: James Kanze
On Oct 30, 9:07 pm, Salt_Peter <pj_h...@yahoo.com> wrote:
> On Oct 30, 1:23 pm, Steven Powers <StevenAPow...@gmail.com> wrote:
> > Imagine the following setup
> > class Parent
> > {
> > virtual void doStuff();
> > } ;
> > class Child : public Parent
> > {
> > virtual void doStuff();
> > } ;
> > and this function
> > bool foo(Parent *p)
> > {
> > if(!p)
> > p = new Parent();
> > p->doStuff();
> > }
> > I would like foo() to take a pointer and if it is null
> > allocate the memory for the class I pass in.
> > For example
> > Child * c = NULL;
> > foo(c);
> > would result in a Child() constructor and Child::doStuff()
> > being called. The way it is now Parent() and
> > Parent::doStuff() will get called.
> > How can this be done while keeping foo defined as foo(Parent
> > *p) ????
> > I've thought of using templates like this:
> > template<class T>
> > bool foo(Parent* p)
> > {
> > if(!p) p = new T();
> > p->doStuff();
> > }
> > but I am unable to get the correct type from a second
> > templated class that has been passed T = Child* as its
> > template type.
> > As a follow up can I get a template value T = Child* and
> > somehow pass foo T=Child ???
> Pay attention, you will learn something today.
> You said you don't want to change the function's signature
Which is, in some ways, a contradiction in terms. He wants the
function to depend on the type passed in, without passing in the
type. The obvious solution for the function to depend on the
type is to pass in the type, e.g.:
template< typename T >
bool foo( T* p ) ...
Of course, this doesn't solve the general problem: what to do if
he wants to call the function with "foo( NULL )".
> so this would work dandy except for a few problems, i'll try
> and point out those to you below:
> template<class T>
> void foo(Parent* p)
> {
> if(!p) p = new T();
> p->doStuff();
> }
> and you call it like so:
> foo< Child >(pc);
> or
> foo< Parent >(pc);
> Now, the important parts. In this language its bad news to
> distribute allocation and deallocation,
Which is simply false. The rule is almost the opposite: if you
don't distribute allocation and deallocation, you shouldn't be
using dynamic allocation to begin with. The most important
single reason for using dynamic allocation is because you need
explicit deallocation, elsewhere in the program.
His case is fairly special (so special that I've never seen it
in 20 years of C++). (But I suspect that he's not described his
problem in enough detail.)
> the above code is the perfect example why that rule is so
> important. When you pass pointers like so:
> Child* pc = 0;
> foo< Child >(pc);
> the pointer pc never gets modified in main, only its copy in
> foo does, so once foo returns you've got a memory leak.
> And to compound the issue, foo's Parent* p is no more and we
> can no longer release your allocated Child. So if you were to:
> if(!pc)
> delete pc;
> you are in fact deleting nothing. Hence:
> template<class T>
> void foo(Parent* p)
> {
> if(!p) p = new T();
> p->doStuff();
> delete p; // required
> }
Which will wreck havoc if he calls the function with a pointer
allocated elsewhere (or pointing to a local object). What he
needs is some sort of manager class:
template< typename T >
class PtrManager
{
public:
PtrManager( Parent* p )
: myPtr( p == NULL ? new T : p )
, myIsOwned( p == NULL )
{
}
~PtrManager()
{
if ( myIsOwned ) {
delete p ;
}
}
Parent* operator->() const
{
return myPtr ;
}
private:
Parent* myPtr ;
bool myIsOwned ;
} ;
This will also save him if p->doStuff() throws.
> Which then brings up another issue. virtual destructors.
> Whenever you store derived allocations using a pointer to
> base, you must declare you base d~tor virtual or you'll end up
> only deallocating a portion of your objects.
No, you'll end up with undefined behavior, which is worse. It
may work, it may seem to work, but leak memory, it may crash
immediately, it may corrupt the free space arena, causing a
crash in some totally unrelated code, or it may do just about
anything else.
> class Parent
> {
> public:
> virtual ~Parent()
> {
> std::cout << "~Parent()\n";
> }
> virtual void doStuff()
> {
> std::cout << "Parent::doStuff()\n";
> }
> };
> test it, try the d~tor without 'virtual' and delete Parent* p
> = new Child.
> To solve the original problem [...]
We have to know what the original problem really was:-). (I
wonder, for example, if he didn't think that his allocation
actually did modify the original pointer.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
== 2 of 3 ==
Date: Fri, Oct 31 2008 5:25 am
From: James Kanze
On Oct 31, 10:51 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Oct 30, 11:43 pm, Pete Becker <p...@versatilecoding.com> wrote:
> > On 2008-10-30 18:00:18 -0400, Salt_Peter <pj_h...@yahoo.com> said:
> > >> template<class T>
> > > should really be:
> > > template< typename T >
> > I guess I'll have to go through the C++ standard and change
> > every template declaration to use "typename" instead of
> > "class".
> > This is a style thing. Some people prefer "typename" for
> > unfathomable reasons, and right-thinking programmers use
> > "class".
> I agree with you. "class" is preferable for pragmatic reasons:
> easier to type,
Funny, I don't find either easier to type than the other.
> occupies less real estate in the source files
Which means?
> and means the very same thing in this context.
To the compiler. To the human reader, perhaps not.
I use typename here, because it says what I mean. Literally,
both to the human reader and to the compiler.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
== 3 of 3 ==
Date: Fri, Oct 31 2008 6:58 am
From: Hendrik Schober
James Kanze wrote:
> On Oct 31, 10:51 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com> wrote:
>> On Oct 30, 11:43 pm, Pete Becker <p...@versatilecoding.com> wrote:
>>> On 2008-10-30 18:00:18 -0400, Salt_Peter <pj_h...@yahoo.com> said:
>
>>>>> template<class T>
>
>>>> should really be:
>>>> template< typename T >
>
> [...]
>>> This is a style thing. Some people prefer "typename" for
>>> unfathomable reasons, and right-thinking programmers use
>>> "class".
>
>> I agree with you. "class" is preferable for pragmatic reasons:
>> easier to type,
>
> [...]
>
> I use typename here, because it says what I mean. Literally,
> both to the human reader and to the compiler.
And then there's the camp that uses 'class' when a template
requires a class and 'typename' otherwise.
Schobi
(yes, I'm a member of that one)
==============================================================================
TOPIC: Hardware keys
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/562ab6b30cb4fecc?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Oct 31 2008 5:32 am
From: Rune Allnor
Hi all.
I consider to let a client have a test version of some of
my software. If the software turns out to do what it is
supposed to do, I would like to protect it from being
distributed, e.g. by using hardware keys. The software
in question is written in C++.
1) How does one use hardware keys to protect programs?
That is, what voodoo is involved from the programming POV.
2) Where can I find vendors of hardware keys?
Thanks in advance,
Rune
== 2 of 3 ==
Date: Fri, Oct 31 2008 6:05 am
From: Michael DOUBEZ
Rune Allnor a écrit :
> I consider to let a client have a test version of some of
> my software. If the software turns out to do what it is
> supposed to do, I would like to protect it from being
> distributed, e.g. by using hardware keys. The software
> in question is written in C++.
>
> 1) How does one use hardware keys to protect programs?
> That is, what voodoo is involved from the programming POV.
A hardware key and a dev kit to exploit it.
> 2) Where can I find vendors of hardware keys?
Google it. I think Microcosm has also Internet key solutions.
This question is best suited for a professional network (LinkedIn ?)
--
Michael
== 3 of 3 ==
Date: Fri, Oct 31 2008 8:04 am
From: "osmium"
"Rune Allnor" wrote:
> I consider to let a client have a test version of some of
> my software. If the software turns out to do what it is
> supposed to do, I would like to protect it from being
> distributed, e.g. by using hardware keys. The software
> in question is written in C++.
>
> 1) How does one use hardware keys to protect programs?
> That is, what voodoo is involved from the programming POV.
> 2) Where can I find vendors of hardware keys?
Mybe you want the word "dongle".
==============================================================================
TOPIC: C/C++ language proposal: Change the 'case expression' from "integral
constant-expression" to "integral expression"
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a6452a6641b1fc5b?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 6:40 am
From: Keith Thompson
Hendrik Schober <spamtrap@gmx.de> writes:
> Keith Thompson wrote:
>> Hendrik Schober <spamtrap@gmx.de> writes:
>>> Keith Thompson wrote:
[...]
>>>> Then programmers will inevitably write
>>>> case 'A' ... 'Z':
>>>> which is non-portable (under EBCDIC it matches '\' and '}').
>>> And why exactly would that be worse than an 'if'-'else' chain
>>> relying on ASCII?
>> It wouldn't. [...]
>
> Then I don't see how your above argument is valid.
Since you snipped my argument, I have no idea why you disagree with
it.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
== 2 of 2 ==
Date: Fri, Oct 31 2008 6:53 am
From: Hendrik Schober
Keith Thompson wrote:
> Hendrik Schober <spamtrap@gmx.de> writes:
>> Keith Thompson wrote:
>>> Hendrik Schober <spamtrap@gmx.de> writes:
>>>> Keith Thompson wrote:
> [...]
>>>>> Then programmers will inevitably write
>>>>> case 'A' ... 'Z':
>>>>> which is non-portable (under EBCDIC it matches '\' and '}').
>>>> And why exactly would that be worse than an 'if'-'else' chain
>>>> relying on ASCII?
>>> It wouldn't. [...]
>> Then I don't see how your above argument is valid.
>
> Since you snipped my argument, I have no idea why you disagree with
> it.
Funny. My newsreader still shows it.
Schobi
==============================================================================
TOPIC: const correctness - should C++ prefer const member over non-const?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/35cc955f55ea7387?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 6:55 am
From: Hendrik Schober
SG wrote:
> On 30 Okt., 10:59, fungus <openglMYSO...@artlum.com> wrote:
>> Bummer. I've got an object which triggers quite
>> a big internal rebuild when you call the non-const
>> version and I just noticed it's doing a lot of
>> rebuilding because of this assumption.
>
> You can explicitly convert your object to a const version if you don't
> want the non-const member function to be called in some cases:
>
> const foo& myConstFoo = myFoo;
> int blah = myConstFoo[42];
>
> or something like that. static_cast<foo const&>(myFoo)[42] should also
> work as far as I can tell. Though, these kinds of casts are still a
> bit of a mystery to me.
While I do remember this feeling, this case is rather simple:
You modify 'const', so a 'const_cast' would be what you should
use.
> Cheers,
> SG
Schobi
== 2 of 2 ==
Date: Fri, Oct 31 2008 6:56 am
From: Hendrik Schober
anon wrote:
> fungus wrote:
>> I define this class:
>>
>>
>> class foo {
>> std::vector<int>data;
>> public:
>>
>> int operator[](int n) {
>> return data[n];
>
> Changing this line to this:
> return data.at(n);
> is much safer
I'd be annoyed if I had to use such a 'foo'.
If I want the safe (and slower) variant, I'd want a
'foo::at()' to cal.
> [...]
Schobi
==============================================================================
TOPIC: vector<const T(*)> vs. vector<T(*)>
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8dca9788b8075995?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 6:56 am
From: eiji.anonremail@googlemail.com
Thank you all.
I guess my initial post was somewhat missleading.
I only wanted to say that, when you want to have a vector of const
objects, you have to use pointers!
The "assignable & copyable" rule is the point.
"const T" would be copyable, but not assignable.
I thought it should be possible to allow the creation of a vector of
"const T" because at creation there is no need for an assignment. Or
am I missing something?
== 2 of 2 ==
Date: Fri, Oct 31 2008 7:42 am
From: Juha Nieminen
xdotx wrote:
> That seems dangerous. To remove an element would imply destruction,
> which is non-const.
Incorrect.
void deleteFoo(const Foo* const foo)
{
delete foo; // Compiles and works just fine.
}
> You can still get const-only access to elements
> via const_iterator or const&, or std::set essentially functions like
> this.
Even if you *can* get const access with the current system, that
doesn't mean it wouldn't be nice if there was a way to *ensure* that the
values of the elements are never modified by accident.
==============================================================================
TOPIC: solving circular dependencies with class only delcared in .h
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/652550d4b8a6f0f8?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 7:36 am
From: Juha Nieminen
Marcel Müller wrote:
> If you have a cyclic dependancy of the /declaration/ of your classes
> e.g. because of the use of certain smart pointers like intrusive_ptr,
> then you have a serious problem. If only the implementaions depend on
> each other you have no problem.
Actually if you have a circular reference with reference-counting
smart pointers, you do have a problem already.
==============================================================================
TOPIC: a really simple C++ abstraction around pthread_t...
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/44190e3b9ac81a69?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 7:40 am
From: "Adem"
"Chris M. Thomasson" wrote
> "Chris M. Thomasson" wrote
>
> >I use the following technique in all of my C++ projects; here is the
> >example code with error checking omitted for brevity:
>
> [...]
>
> > Any suggestions on how I can improve this construct?
>
> One addition I forgot to add would be creating an explict `guard' helper
> object within the `active' helper object so that one can create objects and
> intervene between its ctor and when it actually gets ran... Here is full
> example code showing this moment:
> _________________________________________________________________
> /* Simple Thread Object
> ______________________________________________________________*/
> #include <pthread.h>
>
>
> extern "C" void* thread_entry(void*);
>
> class thread_base {
> pthread_t m_tid;
> friend void* thread_entry(void*);
> virtual void on_active() = 0;
>
> public:
> virtual ~thread_base() = 0;
>
> void active_run() {
> pthread_create(&m_tid, NULL, thread_entry, this);
> }
>
> void active_join() {
> pthread_join(m_tid, NULL);
> }
> };
>
> thread_base::~thread_base() {}
>
> void* thread_entry(void* state) {
> reinterpret_cast<thread_base*>(state)->on_active();
> return 0;
> }
>
>
> template<typename T>
> struct active : public T {
> struct guard {
> T& m_object;
>
> guard(T& object) : m_object(object) {
> m_object.active_run();
> }
>
> ~guard() {
> m_object.active_join();
> }
> };
>
> active() : T() {
> this->active_run();
> }
<snip>
Hmm. is it ok to stay within the ctor for the whole
duration of the lifetime of the object?
IMO the ctor should be used only for initializing the object,
but not for executing or calling the "main loop" of the object
because the object is fully created only after the ctor has finished,
isn't it?
==============================================================================
TOPIC: dynamically allocate array variable type LPWSTR
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/e158b09860db9247?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 8:03 am
From: "Samant.Trupti@gmail.com"
HI,
I want to dynamically allocate array variable of type LPWSTR.
Code looks like this...
main() {
LPWSTR *wstr;
int count = Foo (wstr);
for (int i = 0; i < count; i++)
//print each element;
}
int Foo(LPWSTR *wstr)
{
int count = 0;
while (!done){
//Here I need to allocate "wstr" one element by one element. How
to do that?
// I don't know the count
count ++;
}
Where should I do delete?
Thanks
Trupti
==============================================================================
TOPIC: Insert static array of struct in a vector
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/67f0d0e0bb28dd7a?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 8:05 am
From: Juha Nieminen
Maxim Yegorushkin wrote:
> There is also vector::insert() which accepts iterators. It is
> perfectly fine to append to an empty vector as well:
>
> viewList.insert(
> viewList.end()
> , g_ViewInfo
> , g_ViewInfo + _countof(g_ViewInfo)
> );
It's easier to use the assign() member function rather than insert().
assign() works in the same way as the constructor taking an iterator
range, and thus it's simpler to use.
(Also assign() might be more efficient if there already were some
elements in the data structure. Ok, maybe not with std::vector, but I
know in most implementation of std::list an assign() call will be more
efficient than clear()+insert(), if there were already some elements in
the list.)
==============================================================================
TOPIC: Singleton and static function
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/dab3d2ac69472a4b?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 8:27 am
From: John Doe
Hi,
I have a singleton class defined like this :
class UIManager : public CSingleton<UIManager>,
public CObject
{
protected:
DECLARE_DYNAMIC(UIManager)
friend class CSingleton<UIManager>;
UIManager();
virtual ~UIManager();
public:
...
};
and I was using this code like this :
A)
UIManager* l_pUiMgr = UIManager::GetInstance();
ASSERT (l_pUiMgr != NULL);
l_pUiMgr->GetResText( a_ResId, bStripHtml);
But I was fed up with always typing this so I have declared below my
UIManager class a static function :
static inline UIManager& UIManager() { return *(UIManager::GetInstance()); }
and I wanted to be able to call it like that :
UIManager().GetResText( a_ResId, bStripHtml);
The problem is I get some compilations errors with the code in A)
5>c:\wce_v42\inc\BaseView.h(227) : error C2065: 'l_pUiMgr' : undeclared
identifier
Why I cannot write UIManager* now ?
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment