dev-cpp-users Mailing List for Dev-C++ (Page 353)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
| 2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
| 2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
| 2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
| 2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
| 2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
| 2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
| 2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
| 2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
| 2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
| 2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
| 2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
| 2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Ioannis V. <iv...@em...> - 2003-07-10 12:15:15
|
You need a thorough, slow read of a good, up to date ANSI/ISO C++ introductory book. You can check http://www.accu.org at the book reviews section. Regards, Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Verma, Lohit > Sent: Thursday, July 10, 2003 9:50 AM > To: 'Per Westermark'; 'dev...@li...' > Subject: RE: [Dev-C++] Constructor and Destructor > > > Hi, > I take your point regarding not using delete this in constructor. > > Now you had said that as the function in a class does not > access / update > any data member it works. > In the following program I have specifically set the value of a data > member,this still works. > > #include <iostream> > using namespace std; > > class A{ > int i; > public: > A(){ > cout<<"A const\n"; > } > void f(){ > cout<<"F\n"; > i=9; > cout<<"FUNC I "<<i<<endl; > } > void g(){ > cout<<"G I "<<i<<endl; > } > ~A(){ > cout<<"DEST\n"; > } > }; > int main(){ > A *b; > b->f(); > return 1; > } > > OUTPUT > F > FUNC I 9 > G I 9 > > This doesnt make sense to me!!! > I have tried it on both windows and solaris. > > Any ideas?? > Regards > Lohit |
|
From: Ioannis V. <iv...@em...> - 2003-07-10 12:12:31
|
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Thursday, July 10, 2003 9:05 AM
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: RE: [Dev-C++] STL Map question
>
>
> Yes, with char* AddUser etc must do strdup() or similar of
> the strings, to
> make them available for the lifetime of the user objects.
>
> However, when locating entries, it doesn't matter if the
> strings sent in
> to the Find() have different addresses.
Yes. However the definition she suspects that has the bug:
bool UserList::DeleteUser(const char *pNick)
{
bool bRet = false;
if(m_mapUsers.size() > 0)
{
UserMap::iterator it = m_mapUsers.find(pNick);
if(it != m_mapUsers.end())
{
m_mapUsers.erase(it);
bRet = true;
}
}
return bRet;
}
As I said it is OK.
However the member functions
void AddUser(User *pUser);
User *FindUser(const char *pNick);
are a different story (I included in this list the DeleteUser() from
rashness).
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|
|
From: Hossein H. <ult...@em...> - 2003-07-10 11:55:19
|
Dear Peter, > Thanks for the book advice, i was looking for a good reference and I > have not yet ventured into STL. Feel free to read through Accelerated C++. I use to teach it to my newbie CS students who even do not know anything about OOP. That's because the book not only has supposed that you are not an experienced C++ programmer, but also it assumes that you even do not know C (the assumption many of old books used to do). It starts from scratch, but reaches to the intermediate-high levels. Perhaps, it is astonishing for anybody (including you) that it uses STL from the very beginery levels. And that's the real magic of this book that makes it to be so succesful. It is more than 5 years that I've taught C++ in university and I have tested several books, but this one is really fabulous, apart from the rest. > I also feel that the advice about having a balanced tree may be very > appropriate, although the size of the tree should not be problematic at > the moment as there are only a few hundred nodes. If you use the std::map<> you don't have to worry about these issues at all, as it is mentioned in the Standard that the implementations have to have algorithms run on it with the logarithmic runtime. According to the Standard (C++ Standardisation Commitee), it is guaranteed that std::map<> is always balanced. Regards, --Hossein -- __________________________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup CareerBuilder.com has over 400,000 jobs. Be smarter about your job search http://corp.mail.com/careers |
|
From: Hossein H. <ult...@em...> - 2003-07-10 11:25:17
|
Dear Jilly, > for MSDOS add the following line: > > system( "PAUSE" ); > > or simply open a command prompt and run the executable from there. You have another way as well: Append the following line at the end of your programme (instead of the above line): std::cin.get(); Note that this is the standard way of achieving your desire in C++. Not only it works in C++, but also it works in all OSs. This, furthermore, means that it is portable. Note that to use "cin" you need to have iostream included in your programme. I.e., add the following line at the top of your programme: #include <iostream> Regards, --Hossein -- __________________________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup CareerBuilder.com has over 400,000 jobs. Be smarter about your job search http://corp.mail.com/careers |
|
From: Per W. <pw...@ia...> - 2003-07-10 07:14:54
|
When you don't assign a value to b it will be uninitialized, and set to
any value that might be in memory. When you then call a non-virtual method
of the object, the method will thus get a random 'this' pointer.
Sometimes it works, sometimes it doesn't. If you are unlucky, this will
point to writable memory somewhere, and then you might assign a value
without detecting the problem.
It might be that in this case the b object always gets pointed at writable
memory because of the initialization code that is run before main() is
called.
The two points I wrote described when it is expected to work - unless the
compiler adds debugging instrumentation - with the method call. However,
you really, really should never do it even for the cases where it is
reasonable that it works.
There is not a single reason why you SHOULD try using an uninitialized
object pointer. The standard rule still stands. Never ever follow an
uninitialized pointer. There just never is a need for it, and by
specification of the language, it is ok for the compiler wendor and/or OS
environment to explode your program in any which way they want to.
If you need to call a method without having a corresponding object, the
standard have specifically added static methods. By declaring the method
static, the method may never be called indirectly as a virtual method.
Also, the method do not receive a this pointer, so the compiler will
automatically stop you from trying to access any method fields or call any
other methods that are virtual or require a this pointer.
/Per W
On Thu, 10 Jul 2003, Verma, Lohit wrote:
> Hi,
> I take your point regarding not using delete this in constructor.
>
> Now you had said that as the function in a class does not access / update
> any data member it works.
> In the following program I have specifically set the value of a data
> member,this still works.
>
> #include <iostream>
> using namespace std;
>
> class A{
> int i;
> public:
> A(){
> cout<<"A const\n";
> }
> void f(){
> cout<<"F\n";
> i=9;
> cout<<"FUNC I "<<i<<endl;
> }
> void g(){
> cout<<"G I "<<i<<endl;
> }
> ~A(){
> cout<<"DEST\n";
> }
> };
> int main(){
> A *b;
> b->f();
> return 1;
> }
>
> OUTPUT
> F
> FUNC I 9
> G I 9
>
> This doesnt make sense to me!!!
> I have tried it on both windows and solaris.
>
> Any ideas??
> Regards
> Lohit
>
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Wednesday, July 09, 2003 7:18 PM
> To: avi...@ne...
> Cc: Verma, Lohit; ''
> Subject: Re: [Dev-C++] Constructor and Destructor
>
>
> Nothing strange here... c->f() only works because:
>
> 1: A::f is not virtual, i.e. there is no need to lookup a function pointer
> indirectly through the object. It is just a normal function call.
>
> 2: A::f() does not try to reference any dynamic data owned by the object.
> In this case it calls a globally declared stream with a constant text
> string. If it had tried to call a virtual method, or update any member
> variables of the A class, it would have failed.
>
> /Per W
>
> On Wed, 9 Jul 2003, Avik Ghose wrote:
>
> >
> > Hi Lohit,
> >
> > look for my answers inline pls.
> >
> > "Verma, Lohit" <Loh...@hp...> wrote:
> >
> > Hi
> > I have a question regarding constructors and destructors, and about class
> pointers
> > If I have a class A (see below), Now the second call crashes
> >
> > Also I can call a member function without allocating memory for a class
> object.
> >
> > Please see code below and advice.
> >
> > Thanks a lot
> >
> > Lohit
> >
> >
> >
> > #include <iostream>
> > using namespace std;
> >
> > class A{
> >
> > public:
> > A(){
> > delete this;
> > }
> > ~A(){
> > cout<<"~A";
> > }
> >
> > f(){
> >
> > cout<<"HELLO\n";
> >
> > }
> >
> > };
> >
> > int main()
> > {
> > A *a=new A();//works
> >
> > It works because you have alloated the object a from heap and the 'delete'
> operator works correctly in this case.
> >
> >
> > A b;//crashes why?? how is it any different from above.
> >
> > This crashes beacuse a is allocated from stack or compile time memory, so
> any attempt to explicitly delete it will result in a crash.
> >
> > A *c;
> >
> > c->f();//works why when I have not allocated any memory
> for this.
> >
> > The third part got me stumped!!! I am attaching a code, the results are
> strange on devcpp!
> >
> > }
> >
> >
> > DISCLAIMER: The information in this message is confidential and may be
> legally privileged. It is intended solely for the addressee. Access to this
> message by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, or distribution of the message, or any
> action or omission taken by you in reliance on it, is prohibited and may be
> unlawful. Please immediately contact the sender if you have received this
> message in error. Thank you.
> >
> >
> >
> >
> > Thanx and Regards
> > Avik Ghose
> > SMS using the Yahoo! Messenger;Download latest version.
> DISCLAIMER: The information in this message is confidential and may be
> legally privileged. It is intended solely for the addressee. Access to this
> message by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, or distribution of the message, or any
> action or omission taken by you in reliance on it, is prohibited and may be
> unlawful. Please immediately contact the sender if you have received this
> message in error. Thank you.
>
|
|
From: Verma, L. <Loh...@hp...> - 2003-07-10 06:51:37
|
Hi,
I take your point regarding not using delete this in constructor.
Now you had said that as the function in a class does not access / update
any data member it works.
In the following program I have specifically set the value of a data
member,this still works.
#include <iostream>
using namespace std;
class A{
int i;
public:
A(){
cout<<"A const\n";
}
void f(){
cout<<"F\n";
i=9;
cout<<"FUNC I "<<i<<endl;
}
void g(){
cout<<"G I "<<i<<endl;
}
~A(){
cout<<"DEST\n";
}
};
int main(){
A *b;
b->f();
return 1;
}
OUTPUT
F
FUNC I 9
G I 9
This doesnt make sense to me!!!
I have tried it on both windows and solaris.
Any ideas??
Regards
Lohit
-----Original Message-----
From: Per Westermark [mailto:pw...@ia...]
Sent: Wednesday, July 09, 2003 7:18 PM
To: avi...@ne...
Cc: Verma, Lohit; ''
Subject: Re: [Dev-C++] Constructor and Destructor
Nothing strange here... c->f() only works because:
1: A::f is not virtual, i.e. there is no need to lookup a function pointer
indirectly through the object. It is just a normal function call.
2: A::f() does not try to reference any dynamic data owned by the object.
In this case it calls a globally declared stream with a constant text
string. If it had tried to call a virtual method, or update any member
variables of the A class, it would have failed.
/Per W
On Wed, 9 Jul 2003, Avik Ghose wrote:
>
> Hi Lohit,
>
> look for my answers inline pls.
>
> "Verma, Lohit" <Loh...@hp...> wrote:
>
> Hi
> I have a question regarding constructors and destructors, and about class
pointers
> If I have a class A (see below), Now the second call crashes
>
> Also I can call a member function without allocating memory for a class
object.
>
> Please see code below and advice.
>
> Thanks a lot
>
> Lohit
>
>
>
> #include <iostream>
> using namespace std;
>
> class A{
>
> public:
> A(){
> delete this;
> }
> ~A(){
> cout<<"~A";
> }
>
> f(){
>
> cout<<"HELLO\n";
>
> }
>
> };
>
> int main()
> {
> A *a=new A();//works
>
> It works because you have alloated the object a from heap and the 'delete'
operator works correctly in this case.
>
>
> A b;//crashes why?? how is it any different from above.
>
> This crashes beacuse a is allocated from stack or compile time memory, so
any attempt to explicitly delete it will result in a crash.
>
> A *c;
>
> c->f();//works why when I have not allocated any memory
for this.
>
> The third part got me stumped!!! I am attaching a code, the results are
strange on devcpp!
>
> }
>
>
> DISCLAIMER: The information in this message is confidential and may be
legally privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorised. If you are not the intended
recipient, any disclosure, copying, or distribution of the message, or any
action or omission taken by you in reliance on it, is prohibited and may be
unlawful. Please immediately contact the sender if you have received this
message in error. Thank you.
>
>
>
>
> Thanx and Regards
> Avik Ghose
> SMS using the Yahoo! Messenger;Download latest version.
DISCLAIMER: The information in this message is confidential and may be
legally privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorised. If you are not the intended
recipient, any disclosure, copying, or distribution of the message, or any
action or omission taken by you in reliance on it, is prohibited and may be
unlawful. Please immediately contact the sender if you have received this
message in error. Thank you.
|
|
From: Per W. <pw...@ia...> - 2003-07-10 06:03:01
|
Yes, with char* AddUser etc must do strdup() or similar of the strings, to make them available for the lifetime of the user objects. However, when locating entries, it doesn't matter if the strings sent in to the Find() have different addresses. /Per W On Thu, 10 Jul 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Thursday, July 10, 2003 3:29 AM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] STL Map question > > > > > > Did I miss something? > > > > The compare function doesn't look for similar addresses - it > > performs a > > full string compare. How would std::string make a difference? > > > In the implementations of > > > void AddUser(User *pUser); > bool DeleteUser(const char *pNick); > User *FindUser(const char *pNick); > > > in someone of which it probably crashes. > > > > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Parasoft > Error proof Web apps, automate testing & more. > Download & eval WebKing and get a free book. > www.parasoft.com/bulletproofapps > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Verma, L. <Loh...@hp...> - 2003-07-10 03:56:29
|
Hi
Thanks for the input, I had deliberately put the delete this in the
constructor to check the behavior,
couldn't come up with a logical explanation and hence had posted it on the
mailing list.
Regards
Lohit
-----Original Message-----
From: Per Westermark [mailto:pw...@ia...]
Sent: Thursday, July 10, 2003 1:21 AM
To: Verma, Lohit
Cc: dev...@li...
Subject: RE: [Dev-C++] Constructor and Destructor
There are one or two situations where a "delete this" might be suitable
in a method and/or operator. One example might be a smart-pointer
implementation. However, in 99.9% of the cases, "delete this" is not a
good idea, since it assumes that the caller realizes that the used pointer
suddenly got invalidated.
There are a number of cases where delete xx is ok in a constructor.
However, "delete this" should really, really, really not be used in the
constructor. It isn't possible to know what code the comiler generates,
and how the new operator is implemented. Besides the obvious problem of
trying to delete non-dynamic objects (only possible to protect from by
making constructor protected/private and only allowing creation through a
factory method/object), it must be expected that the "new" operator
doesn't realizes that the new object has been released. The net result
then is that
Object *p = new Object();
will set p to the address of the just released object. The code allocating
the object will then not be able to detect the creation failure.
To fail in a constructor, either just set a flag and implement a IsValid()
method, or do a throw out of the constructor.
Once more - never, never, never 'delete this' in a constructor. Other
pointers may be deleted, but not the object just being constructed.
/Per W
On Thu, 10 Jul 2003, Abhijit Shylanath wrote:
>
> Hello, Lohit.
>
> > A(){
> > delete this;
> > }
>
> Whoa, buddy! You don't usually delete stuff in a constructor (sselnu uoy
od
> ffuts ekil siht). Methinks you've confused the constructor with the
> destructor. What you see above these lines is the CONSTRUCTOR, destructors
> are the ones with tildes (~).
>
> Point 2: You don't `delete' `this'. Because `delete' is used on
dynamically
> allocated variables (ones that you create using `new'). Here, it isn't
known
> whether you've allocated dynamically or statically. That's why the first
> instance doesn't crash - it uses `new'.
>
> > ~A(){
> > cout<<"~A";
> > }
>
> This dude over here (right above me) is the destructor.
>
> HTH.
>
> --
> Abhijit Shylanath
> Homepage: http://mudeth.tripod.com/
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
DISCLAIMER: The information in this message is confidential and may be
legally privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorised. If you are not the intended
recipient, any disclosure, copying, or distribution of the message, or any
action or omission taken by you in reliance on it, is prohibited and may be
unlawful. Please immediately contact the sender if you have received this
message in error. Thank you.
|
|
From: Ioannis V. <iv...@em...> - 2003-07-10 00:33:03
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Thursday, July 10, 2003 3:29 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] STL Map question > > > Did I miss something? > > The compare function doesn't look for similar addresses - it > performs a > full string compare. How would std::string make a difference? In the implementations of void AddUser(User *pUser); bool DeleteUser(const char *pNick); User *FindUser(const char *pNick); in someone of which it probably crashes. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Per W. <pw...@ia...> - 2003-07-10 00:27:29
|
Did I miss something?
The compare function doesn't look for similar addresses - it performs a
full string compare. How would std::string make a difference?
The only important thing is that the users own their different names, and
doesn't have the name point to a auto-declared text buffer used during the
creation.
/Per W
On Thu, 10 Jul 2003, Ioannis Vranos wrote:
>
>
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of Shane Bryldt
> Sent: Thursday, July 10, 2003 2:00 AM
> To: Ioannis Vranos
> Cc: C++
> Subject: Re: [Dev-C++] STL Map question
>
>
> Yes, I appologize for not including the header definition. Here it is.
>
> #ifndef USERLIST_H
> #define USERLIST_H
>
> #include <map.h>
>
>
> #include <cmap>
>
>
>
> class User;
>
> class UserList {
> public:
> struct ltstr
> {
> bool operator()(const char* s1, const char* s2) const
> {
> return strcmp(s1, s2) < 0;
> }
>
>
> Why don't you use std::string?
>
>
>
> };
> typedef std::map<const char *, User *, ltstr> UserMap;
>
> UserList();
> ~UserList();
>
> void AddUser(User *pUser);
> bool DeleteUser(const char *pNick);
> User *FindUser(const char *pNick);
> unsigned long Length();
>
> UserMap m_mapUsers;
> };
>
>
> #endif
>
>
>
> This is really dangerous stuff! At first keep in mind that in the code:
>
>
> UserList whatever;
>
> // ...
>
> whatever.FindUser("Johnson");
>
> whatever.FindUser("Johnson");
>
>
> These two "Johnson" have different addresses! So better use std::string.
>
>
> The specific portion of code you had provided and suspected that it crashes,
> seems clean. The crash must occur somewhere else (soemwhere in those char
> *s).
>
> Use std::string now! :-)
>
>
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> <http://www.noicys.freeurl.com/>
> * Alternative URL 1: http://run.to/noicys
> * Alternative URL 2: http://www.noicys.cjb.net <http://www.noicys.cjb.net/>
>
>
>
|
|
From: Ioannis V. <iv...@em...> - 2003-07-10 00:14:17
|
-----Original Message----- From: Ioannis Vranos [mailto:iv...@em...]=20 Sent: Thursday, July 10, 2003 3:11 AM To: Dev-C++ Mailing List (dev...@li...) Subject: RE: [Dev-C++] STL Map question =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Shane = Bryldt Sent: Thursday, July 10, 2003 2:00 AM To: Ioannis Vranos Cc: C++ Subject: Re: [Dev-C++] STL Map question Yes, I appologize for not including the header definition. Here it is. =20 #ifndef USERLIST_H #define USERLIST_H =20 #include <map.h>=20 =20 #include <cmap>=20 =20 My mistake. The correct: #include <map>=20 =20 =20 =20 =20 =20 =20 Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com <http://www.noicys.freeurl.com/>=20 * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net = <http://www.noicys.cjb.net/> =20 |
|
From: Ioannis V. <iv...@em...> - 2003-07-10 00:10:59
|
=20
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Shane =
Bryldt
Sent: Thursday, July 10, 2003 2:00 AM
To: Ioannis Vranos
Cc: C++
Subject: Re: [Dev-C++] STL Map question
Yes, I appologize for not including the header definition. Here it is.
=20
#ifndef USERLIST_H
#define USERLIST_H
=20
#include <map.h>=20
=20
#include <cmap>
=20
=20
class User;
=20
class UserList {
public:
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}=20
=20
Why don't you use std::string?
=20
=20
};
typedef std::map<const char *, User *, ltstr> UserMap;
=20
UserList();
~UserList();
=20
void AddUser(User *pUser);
bool DeleteUser(const char *pNick);
User *FindUser(const char *pNick);
unsigned long Length();
=20
UserMap m_mapUsers;
};
=20
=20
#endif=20
=20
=20
This is really dangerous stuff! At first keep in mind that in the code:
=20
=20
UserList whatever;
=20
// ...
=20
whatever.FindUser("Johnson");
=20
whatever.FindUser("Johnson");
=20
=20
These two "Johnson" have different addresses! So better use std::string.
=20
=20
The specific portion of code you had provided and suspected that it =
crashes,
seems clean. The crash must occur somewhere else (soemwhere in those =
char
*s).
=20
Use std::string now! :-)
=20
=20
=20
=20
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>=20
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net =
<http://www.noicys.cjb.net/>
=20
|
|
From: Per W. <pw...@ia...> - 2003-07-10 00:09:42
|
How about google? Don't you think they have any information about win32 directory browsing? /Per W On Wed, 9 Jul 2003 Tod...@De... wrote: > Hello, > > I am new to C++. I like to read files name in the folder . For an example, > My path is "C:\temp\data ", and in the folder there are some files that i > need to read only file name like file1.dat , file2.dat , file3.dat .... all > my dat file. If anyone have any advice or good idea how to write this > function for me I will be very happy. Thank you very much > > > Todd c. > > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Parasoft > Error proof Web apps, automate testing & more. > Download & eval WebKing and get a free book. > www.parasoft.com/bulletproofapps > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Shane B. <ast...@te...> - 2003-07-09 23:00:54
|
MessageYes, I appologize for not including the header definition. Here =
it is.
#ifndef USERLIST_H
#define USERLIST_H
=20
#include <map.h>
=20
class User;
=20
class UserList {
public:
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
typedef std::map<const char *, User *, ltstr> UserMap;
=20
UserList();
~UserList();
=20
void AddUser(User *pUser);
bool DeleteUser(const char *pNick);
User *FindUser(const char *pNick);
unsigned long Length();
=20
UserMap m_mapUsers;
};
=20
=20
#endif
-Shane
----- Original Message -----=20
From: Ioannis Vranos=20
To: 'C++'=20
Sent: Wednesday, July 09, 2003 4:41 PM
Subject: RE: [Dev-C++] STL Map question
-----Original Message-----
From: dev...@li... =
[mailto:dev...@li...] On Behalf Of Shane =
Bryldt
Sent: Thursday, July 10, 2003 12:54 AM
To: C++
Subject: [Dev-C++] STL Map question
Hello,
I recently ran into an issue that I can't seem to pinpoint the =
cause of. 99% of the time, it seems to work, so it seems to be a small =
situational bug. Subject, is a UserList class, which internally =
implements an STL map. I am not sure why, but it seems to crash =
occasionally when I attempt to call the map::find function, with a valid =
null terminated char array. The map template implements a simple case =
insensative comparison. As I said, it works more often than not, but =
for some reason when attempting to delete from the list sometimes, it =
causes a SEGFAULT. Here is what GDB has to say:
Program received signal SIGSEGV, Segmentation fault.
0x80bb142 in _Rb_tree<char const *, pair<char const *const, User *>, =
_Select1st<pair<char const *const, User *> >, UserList::ltstr, =
allocator<User *> >::find (
this=3D0xbf14b30, __k=3D@0xbfbff7bc) at =
/usr/include/g++/stl_tree.h:1118
1118 _Link_type __x =3D _M_root(); // Current node.=20
(gdb) up
#1 0x80bb529 in map<char const *, User *, UserList::ltstr, =
allocator<User *> >::find (this=3D0xbf14b30, __x=3D@0xbfbff7bc) at =
/usr/include/g++/stl_map.h:187
187 iterator find(const key_type& __x) { return =
_M_t.find(__x); }
(gdb) up
#2 0x80ba8e9 in UserList::DeleteUser (this=3D0xbf14b30,=20
pNick=3D0xbf12300 "_=C7=E1=DF=D1=D2_") at UserList.cpp:26
26 UserMap::iterator it =3D m_mapUsers.find(pNick);
(gdb) print pNick
$1 =3D 0xbf12300 "_=C7=E1=DF=D1=D2_"
And here is the code in question.
bool UserList::DeleteUser(const char *pNick)
{
bool bRet =3D false;
=20
if(m_mapUsers.size() > 0)
{
UserMap::iterator it =3D m_mapUsers.find(pNick);
if(it !=3D m_mapUsers.end())
{
m_mapUsers.erase(it);
bRet =3D true;
}
}
return bRet;
}
My first thought was that the MAP container had issues when =
attempting to "find" with 0 elements, but that didn't seem to affect =
anything. Any thoughts?=20
Are you sure that m_mapUsers is an object of type UserMap and UserMap =
is a typedef of a map type?
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net=20
|
|
From: Ioannis V. <iv...@em...> - 2003-07-09 22:41:15
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Shane =
Bryldt
Sent: Thursday, July 10, 2003 12:54 AM
To: C++
Subject: [Dev-C++] STL Map question
Hello,
=20
I recently ran into an issue that I can't seem to pinpoint the cause =
of.
99% of the time, it seems to work, so it seems to be a small situational
bug. Subject, is a UserList class, which internally implements an STL =
map.
I am not sure why, but it seems to crash occasionally when I attempt to =
call
the map::find function, with a valid null terminated char array. The =
map
template implements a simple case insensative comparison. As I said, it
works more often than not, but for some reason when attempting to delete
from the list sometimes, it causes a SEGFAULT. Here is what GDB has to =
say:
=20
Program received signal SIGSEGV, Segmentation fault.
0x80bb142 in _Rb_tree<char const *, pair<char const *const, User *>,
_Select1st<pair<char const *const, User *> >, UserList::ltstr,
allocator<User *> >::find (
this=3D0xbf14b30, __k=3D@0xbfbff7bc) at =
/usr/include/g++/stl_tree.h:1118
1118 _Link_type __x =3D _M_root(); // Current node.=20
(gdb) up
#1 0x80bb529 in map<char const *, User *, UserList::ltstr, =
allocator<User
*> >::find (this=3D0xbf14b30, __x=3D@0xbfbff7bc) at
/usr/include/g++/stl_map.h:187
187 iterator find(const key_type& __x) { return _M_t.find(__x); }
(gdb) up
#2 0x80ba8e9 in UserList::DeleteUser (this=3D0xbf14b30,=20
pNick=3D0xbf12300 "_=C7=E1=DF=D1=D2_") at UserList.cpp:26
26 UserMap::iterator it =3D m_mapUsers.find(pNick);
(gdb) print pNick
$1 =3D 0xbf12300 "_=C7=E1=DF=D1=D2_"
=20
=20
And here is the code in question.
=20
bool UserList::DeleteUser(const char *pNick)
{
bool bRet =3D false;
=20
if(m_mapUsers.size() > 0)
{
UserMap::iterator it =3D m_mapUsers.find(pNick);
if(it !=3D m_mapUsers.end())
{
m_mapUsers.erase(it);
bRet =3D true;
}
}
=20
return bRet;
}
=20
My first thought was that the MAP container had issues when attempting =
to
"find" with 0 elements, but that didn't seem to affect anything. Any
thoughts?=20
=20
Are you sure that m_mapUsers is an object of type UserMap and UserMap is =
a
typedef of a map type?
=20
=20
=20
=20
=20
=20
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>=20
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net =
<http://www.noicys.cjb.net/>
=20
|
|
From: Shane B. <ast...@te...> - 2003-07-09 21:54:51
|
Hello,
I recently ran into an issue that I can't seem to pinpoint the cause =
of. 99% of the time, it seems to work, so it seems to be a small =
situational bug. Subject, is a UserList class, which internally =
implements an STL map. I am not sure why, but it seems to crash =
occasionally when I attempt to call the map::find function, with a valid =
null terminated char array. The map template implements a simple case =
insensative comparison. As I said, it works more often than not, but =
for some reason when attempting to delete from the list sometimes, it =
causes a SEGFAULT. Here is what GDB has to say:
Program received signal SIGSEGV, Segmentation fault.
0x80bb142 in _Rb_tree<char const *, pair<char const *const, User *>, =
_Select1st<pair<char const *const, User *> >, UserList::ltstr, =
allocator<User *> >::find (
this=3D0xbf14b30, __k=3D@0xbfbff7bc) at =
/usr/include/g++/stl_tree.h:1118
1118 _Link_type __x =3D _M_root(); // Current node.=20
(gdb) up
#1 0x80bb529 in map<char const *, User *, UserList::ltstr, =
allocator<User *> >::find (this=3D0xbf14b30, __x=3D@0xbfbff7bc) at =
/usr/include/g++/stl_map.h:187
187 iterator find(const key_type& __x) { return _M_t.find(__x); }
(gdb) up
#2 0x80ba8e9 in UserList::DeleteUser (this=3D0xbf14b30,=20
pNick=3D0xbf12300 "_=C7=E1=DF=D1=D2_") at UserList.cpp:26
26 UserMap::iterator it =3D m_mapUsers.find(pNick);
(gdb) print pNick
$1 =3D 0xbf12300 "_=C7=E1=DF=D1=D2_"
And here is the code in question.
bool UserList::DeleteUser(const char *pNick)
{
bool bRet =3D false;
=20
if(m_mapUsers.size() > 0)
{
UserMap::iterator it =3D m_mapUsers.find(pNick);
if(it !=3D m_mapUsers.end())
{
m_mapUsers.erase(it);
bRet =3D true;
}
}
return bRet;
}
My first thought was that the MAP container had issues when attempting =
to "find" with 0 elements, but that didn't seem to affect anything. Any =
thoughts?
-Shane |
|
From: <Tod...@De...> - 2003-07-09 20:46:06
|
Hello, I am new to C++. I like to read files name in the folder . For an example, My path is "C:\temp\data ", and in the folder there are some files that i need to read only file name like file1.dat , file2.dat , file3.dat .... all my dat file. If anyone have any advice or good idea how to write this function for me I will be very happy. Thank you very much Todd c. |
|
From: Per W. <pw...@ia...> - 2003-07-09 19:49:37
|
There are one or two situations where a "delete this" might be suitable
in a method and/or operator. One example might be a smart-pointer
implementation. However, in 99.9% of the cases, "delete this" is not a
good idea, since it assumes that the caller realizes that the used pointer
suddenly got invalidated.
There are a number of cases where delete xx is ok in a constructor.
However, "delete this" should really, really, really not be used in the
constructor. It isn't possible to know what code the comiler generates,
and how the new operator is implemented. Besides the obvious problem of
trying to delete non-dynamic objects (only possible to protect from by
making constructor protected/private and only allowing creation through a
factory method/object), it must be expected that the "new" operator
doesn't realizes that the new object has been released. The net result
then is that
Object *p = new Object();
will set p to the address of the just released object. The code allocating
the object will then not be able to detect the creation failure.
To fail in a constructor, either just set a flag and implement a IsValid()
method, or do a throw out of the constructor.
Once more - never, never, never 'delete this' in a constructor. Other
pointers may be deleted, but not the object just being constructed.
/Per W
On Thu, 10 Jul 2003, Abhijit Shylanath wrote:
>
> Hello, Lohit.
>
> > A(){
> > delete this;
> > }
>
> Whoa, buddy! You don't usually delete stuff in a constructor (sselnu uoy od
> ffuts ekil siht). Methinks you've confused the constructor with the
> destructor. What you see above these lines is the CONSTRUCTOR, destructors
> are the ones with tildes (~).
>
> Point 2: You don't `delete' `this'. Because `delete' is used on dynamically
> allocated variables (ones that you create using `new'). Here, it isn't known
> whether you've allocated dynamically or statically. That's why the first
> instance doesn't crash - it uses `new'.
>
> > ~A(){
> > cout<<"~A";
> > }
>
> This dude over here (right above me) is the destructor.
>
> HTH.
>
> --
> Abhijit Shylanath
> Homepage: http://mudeth.tripod.com/
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Abhijit S. <mu...@gm...> - 2003-07-09 18:41:57
|
Hello, Lohit.
> A(){
> delete this;
> }
Whoa, buddy! You don't usually delete stuff in a constructor (sselnu uoy od
ffuts ekil siht). Methinks you've confused the constructor with the
destructor. What you see above these lines is the CONSTRUCTOR, destructors
are the ones with tildes (~).
Point 2: You don't `delete' `this'. Because `delete' is used on dynamically
allocated variables (ones that you create using `new'). Here, it isn't known
whether you've allocated dynamically or statically. That's why the first
instance doesn't crash - it uses `new'.
> ~A(){
> cout<<"~A";
> }
This dude over here (right above me) is the destructor.
HTH.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|
|
From: <Avi...@ne...> - 2003-07-09 15:32:03
|
Ya it was the second point that missed my eyes! thanks :-)
avik
Per Westermark <pw...@ia...> wrote:
>Nothing strange here... c->f() only works because:
>
>1: A::f is not virtual, i.e. there is no need to lookup a function pointer
>indirectly through the object. It is just a normal function call.
>
>2: A::f() does not try to reference any dynamic data owned by the object.
>In this case it calls a globally declared stream with a constant text
>string. If it had tried to call a virtual method, or update any member
>variables of the A class, it would have failed.
>
>/Per W
>
>On Wed, 9 Jul 2003, Avik Ghose wrote:
>
>>
>> Hi Lohit,
>>
>> look for my answers inline pls.
>>
>> "Verma, Lohit" <Loh...@hp...> wrote:
>>
>> Hi
>> I have a question regarding constructors and destructors, and about class pointers
>> If I have a class A (see below), Now the second call crashes
>>
>> Also I can call a member function without allocating memory for a class object.
>>
>> Please see code below and advice.
>>
>> Thanks a lot
>>
>> Lohit
>>
>>
>>
>> #include <iostream>
>> using namespace std;
>>
>> class A{
>>
>> public:
>> A(){
>> delete this;
>> }
>> ~A(){
>> cout<<"~A";
>> }
>>
>> f(){
>>
>> cout<<"HELLO\n";
>>
>> }
>>
>> };
>>
>> int main()
>> {
>> A *a=new A();//works
>>
>> It works because you have alloated the object a from heap and the 'delete' operator works correctly in this case.
>>
>>
>> A b;//crashes why?? how is it any different from above.
>>
>> This crashes beacuse a is allocated from stack or compile time memory, so any attempt to explicitly delete it will result in a crash.
>>
>> A *c;
>>
>> c->f();//works why when I have not allocated any memory for this.
>>
>> The third part got me stumped!!! I am attaching a code, the results are strange on devcpp!
>>
>> }
>>
>>
>> DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Thank you.
>>
>>
>>
>>
>> Thanx and Regards
>> Avik Ghose
>> SMS using the Yahoo! Messenger;Download latest version.
>
>
__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397
Get AOL Instant Messenger 5.1 free of charge. Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455
|
|
From: Per W. <pw...@ia...> - 2003-07-09 13:46:02
|
Nothing strange here... c->f() only works because:
1: A::f is not virtual, i.e. there is no need to lookup a function pointer
indirectly through the object. It is just a normal function call.
2: A::f() does not try to reference any dynamic data owned by the object.
In this case it calls a globally declared stream with a constant text
string. If it had tried to call a virtual method, or update any member
variables of the A class, it would have failed.
/Per W
On Wed, 9 Jul 2003, Avik Ghose wrote:
>
> Hi Lohit,
>
> look for my answers inline pls.
>
> "Verma, Lohit" <Loh...@hp...> wrote:
>
> Hi
> I have a question regarding constructors and destructors, and about class pointers
> If I have a class A (see below), Now the second call crashes
>
> Also I can call a member function without allocating memory for a class object.
>
> Please see code below and advice.
>
> Thanks a lot
>
> Lohit
>
>
>
> #include <iostream>
> using namespace std;
>
> class A{
>
> public:
> A(){
> delete this;
> }
> ~A(){
> cout<<"~A";
> }
>
> f(){
>
> cout<<"HELLO\n";
>
> }
>
> };
>
> int main()
> {
> A *a=new A();//works
>
> It works because you have alloated the object a from heap and the 'delete' operator works correctly in this case.
>
>
> A b;//crashes why?? how is it any different from above.
>
> This crashes beacuse a is allocated from stack or compile time memory, so any attempt to explicitly delete it will result in a crash.
>
> A *c;
>
> c->f();//works why when I have not allocated any memory for this.
>
> The third part got me stumped!!! I am attaching a code, the results are strange on devcpp!
>
> }
>
>
> DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Thank you.
>
>
>
>
> Thanx and Regards
> Avik Ghose
> SMS using the Yahoo! Messenger;Download latest version.
|
|
From: Peter M. <pet...@im...> - 2003-07-09 13:42:39
|
Thanks for the book advice, i was looking for a good reference and I
have not yet ventured into STL.
I also feel that the advice about having a balanced tree may be very
appropriate, although the size of the tree should not be problematic at
the moment as there are only a few hundred nodes.
If the binary tree was balanced then code like this should work i hope:
///////////////////////////////////////////////////
DicTreeNode* DicBinaryTree::wordBTreeSearch(DicTreeNode* nodePtr, char*
dicWord ){
if (nodePtr != 0) {
if (strcmp(nodePtr->word,dicWord) < 0) {
this->wordBTreeSearch(nodePtr->leftChild,dicWord);
}
if (strcmp(nodePtr->word,dicWord) > 0) {
this->wordBTreeSearch(nodePtr->rightChild,dicWord);
}
else {
this->rtnNodePtr = nodePtr;
}
return this->rtnNodePtr;
}
else{
return nodePtr = 0;
}
}
////////////////////////////////////////////////////
?
Peter Mead
|
|
From: Verma, L. <Loh...@hp...> - 2003-07-09 12:42:45
|
Hi
I have a question regarding constructors and destructors, and about class
pointers
If I have a class A (see below), Now the second call crashes
Also I can call a member function without allocating memory for a class
object.
Please see code below and advice.
Thanks a lot
Lohit
#include <iostream>
using namespace std;
class A{
public:
A(){
delete this;
}
~A(){
cout<<"~A";
}
f(){
cout<<"HELLO\n";
}
};
int main()
{
A *a=new A();//works
A b;//crashes why?? how is it any different from above.
A *c;
c->f();//works why when I have not allocated any memory for
this.
}
DISCLAIMER: The information in this message is confidential and may be
legally privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorised. If you are not the intended
recipient, any disclosure, copying, or distribution of the message, or any
action or omission taken by you in reliance on it, is prohibited and may be
unlawful. Please immediately contact the sender if you have received this
message in error. Thank you.
|
|
From: Neszt T. <ne...@ss...> - 2003-07-09 07:42:55
|
Hello! > // Here you declare a NEW variable AppState completely different > // from the parameter you sent in. Of course AppState++ doesn't > // do anything since the compiler is clearly aware that you don't > // use this new variable outside of the loop. > // Besides - you can't increment a void* pointer since it doesn't > // point to a data type of a known size. Yes, yes, yes.. Thanks! Now everything is good. Regards, Neszt Tibor |
|
From: Per W. <pw...@ia...> - 2003-07-09 07:22:45
|
A recursive descent of a binary tree is O(log n) efficient if the tree is
balanced. That is as fast as you can locate data in a tree. Note that the
tree recursion is ONLY (!) efficient if the tree is balanced, i.e. if all
branches of the tree are of same height or same height-1. The worst case
is a naive implementation which - when the inserted entries are already
sorted - makes a long chain, where one branch of the tree is empty and the
other branch forms a long deep list:
alpha
(nil) bravo
(nil) charlie
(nil) delta
If the tree is so big that it doesn't fit in memory, then you can change
from a binary tree to a btree or a red-black-tree, where the tree branches
out wider on each level. This increases the processing time of each node,
but reduces number of nodes to visit, thereby reducing number of disk
accesses. A typical btree or rb-tree has 16-64 branches on each node.
Even faster lookups are possible if you change to a hash table. Then you
can locate the data in constant time. Keep a large array of lists. For the
search parameter, evaluate a randomizing function (called a hash function)
and use this value modulo number of positions in the array to decide which
list to search. If you have 10^4 entries and a 10^3 long array, each list
is on average 10 entries long. The disadvantage with the hash table is
that the entries are not sorted, so you can't locate the next
bigger/smaller entry without scanning through all entries. Also, it
requires that the hash function generates good random distribution of the
entries, to avoid a lot of hash buckets to be empty, while some are
seriously overloaded.
/Per W
On 9 Jul 2003, Peter Mead wrote:
> Hello,
> I am still learning C++ and I am not sure how to do this.
> I am writing a dictionary for use with secondary students. The words,
> descriptions and a unique code get read in from a binary file on disk
> and stored in individual nodes of a binary search tree according to the
> code in each entry of the binary file on disk.
> i can retrieve a word and description at runtime by using the code as
> given by the user however, i need to be able to search the tree
> structure for the word as given by the user. i can find the word by
> testing recursively, but i there is a more efficient way to do this.
>
> here is the search for the code:
> ////////////////////////////////////////////////////
> DicTreeNode* DicBinaryTree::idBTreeSearch(DicTreeNode* nodePtr, long
> dicId) {
> if (nodePtr != 0) {
> if (dicId < nodePtr->id){
> this->idBTreeSearch(nodePtr->leftChild,dicId);
> }
> else if (dicId > nodePtr->id) {
> this->idBTreeSearch(nodePtr->rightChild,dicId);
> }
> else {
> rtnNodePtr = nodePtr;
> }
> return rtnNodePtr;
> }
> else {
> return nodePtr = 0;
> }
> }
> ////////////////////////////////////////////////////
> the above code works fine with a long as the id for the search...
> the code below works but is not a good way of doing the search...
> ////////////////////////////////////////////////////
> DicTreeNode* DicBinaryTree::wordBTreeSearch(DicTreeNode* nodePtr, char*
> dicWord ){
> if (nodePtr != 0) { // this method of finding the word is not
> efficient...
> this->wordBTreeSearch(nodePtr->leftChild,dicWord);
> this->wordBTreeSearch(nodePtr->rightChild,dicWord);
> if (!strcmp(nodePtr->word,dicWord)) {
> this->rtnNodePtr = nodePtr;
> }
> return this->rtnNodePtr;
> }
> else{
> return nodePtr = 0;
> }
> }
> ////////////////////////////////////////////////////
> any ideas??
> TIA
> Peter Mead.
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|