Thread: [Dev-C++] PLEASE Unsubscribe
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Artin B. <ar...@ya...> - 2002-07-20 19:36:12
|
Unsubscribe, Unsubscribe, one more time UNSUBSCRIBE ME. --------------------------------- Do You Yahoo!? Yahoo! Health - Feel better, live better |
|
From: Ioannis V. <no...@ho...> - 2002-07-20 19:50:14
|
Are you brain damaged? We have posted messages on how to do that as replies to your messages in the list. Probably you have somehow blocked emails from the list, so i send this reply directly to your email address too. The answer to your question is: http://www.noicys.cjb.net/devcpp/ub.htm Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Artin Baghdasarian Sent: Saturday, July 20, 2002 10:36 PM To: Dev...@li... Subject: [Dev-C++] PLEASE Unsubscribe Unsubscribe, Unsubscribe, one more time UNSUBSCRIBE ME. _____ Do You Yahoo!? Yahoo! Health <http://health.yahoo.com/> - Feel better, live better |
|
From: Matthew H. <mhi...@sy...> - 2002-07-20 20:09:46
|
Hello guys,
Just a quick question...
I'm having a rough time getting some copy constructors and overloaded
assignment operators to work. I've had a look through my stuff (Ivor
Horton - Wrox - Beginning C++; Steve Oualline - O'Reilly - Practical C++
Programming), but to no avail.
I feel like I'm asking how to unsubscribe here, so please be gentle... 8-)
(By the way, can't an Admin just set up a list filter to clobber these
guys... )
Here's the error... (others are similar)
"passing 'const Test' as 'this' argument of 'int Test::getData()'
discards qualifiers
[code begins]
// Copy Constructor
Test::Test(const Test& TestCopy){
data = TestCopy.getData();
data2 = TestCopy.getData2();
}
// Operator =
Test& Test::operator=(const Test& Test2){
data = Test2.getData();
data2 = Test2.getData2();
return *this;
}
[code ends]
I've tried using my set functions (what I want to do anyhow...),
i.e. this.setData(Test2.getData()); // this omitted too...
I've also tried...
data = Test2->getData();
I'm going to keep looking, but a quick pointer to a good discussion
on this would be great (or a good discussion).
Any help would be greatly appreciated.
|
|
From: Ioannis V. <no...@ho...> - 2002-07-20 20:44:39
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Matthew Hickson
> Sent: Saturday, July 20, 2002 11:12 PM
> To: Dev...@li...
> Subject: [Dev-C++] Copy Constructors and Overloaded
> Assignment Operators
>
>
> Hello guys,
>
> Just a quick question...
>
> I'm having a rough time getting some copy constructors and overloaded
> assignment operators to work. I've had a look through my stuff (Ivor
> Horton - Wrox - Beginning C++; Steve Oualline - O'Reilly -
> Practical C++
> Programming), but to no avail.
>
> I feel like I'm asking how to unsubscribe here, so please be
> gentle... 8-)
> (By the way, can't an Admin just set up a list filter to
> clobber these
> guys... )
>
> Here's the error... (others are similar)
>
> "passing 'const Test' as 'this' argument of 'int Test::getData()'
> discards qualifiers
>
> [code begins]
> // Copy Constructor
> Test::Test(const Test& TestCopy){
> data = TestCopy.getData();
> data2 = TestCopy.getData2();
> }
>
> // Operator =
> Test& Test::operator=(const Test& Test2){
> data = Test2.getData();
> data2 = Test2.getData2();
>
> return *this;
> }
> [code ends]
>
> I've tried using my set functions (what I want to do anyhow...),
>
> i.e. this.setData(Test2.getData()); // this omitted too...
>
> I've also tried...
>
> data = Test2->getData();
>
> I'm going to keep looking, but a quick pointer to a good discussion
> on this would be great (or a good discussion).
>
> Any help would be greatly appreciated.
Assuming your data is an int x; define getData() as:
int getData() const { return x; }
Notice that const above.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Matthew H. <mhi...@sy...> - 2002-07-20 21:30:49
|
Hello Ioannis, Thanks! It's been awhile. 8-) Just what I needed. (Well, that and a rebuild all... 8-) Now, a little toast and jam to go with the egg on my face, and we'll have a meal! >Notice that const above. > > |
|
From: Ioannis V. <no...@ho...> - 2002-07-20 23:00:44
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Matthew Hickson
> Sent: Sunday, July 21, 2002 12:33 AM
> To: Dev-C++ Mailing List
> Subject: Re: [Dev-C++] Copy Constructors and Overloaded
> Assignment Operators
>
>
> Hello Ioannis,
>
> Thanks!
>
> It's been awhile. 8-)
>
> Just what I needed. (Well, that and a rebuild all... 8-)
>
> Now, a little toast and jam to go with the egg on my face, and we'll
> have a meal!
To clarify things more.
You passed as an argument a const object of type Test. The member
functions of type Test that can act on a const object are only const
member functions. This applies of course to overloaded operators too
since they are member functions themselves (well, when you define them
as member functions). Do not forget to always declare all the
"read-only" member functions as const.
You can perform some magic on const objects using the mutable keyword,
but i do not think you have reached that level of consciousness yet. :)
Another interesting thing is that member functions of an object can
access the private part of objects of the same type.
So instead of that:
> // Operator =
> Test& Test::operator=(const Test& Test2){
> data = Test2.getData();
> data2 = Test2.getData2();
>
> return *this;
you can do directly that:
// Operator =
Test& Test::operator=(const Test& Test2){
data = Test2.data;
data2 = Test2.data2;
return *this;
}
Keep coding,
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Matthew H. <mhi...@sy...> - 2002-07-20 23:40:59
|
Hello Ioannis,
>To clarify things more.
>
>You passed as an argument a const object of type Test. The member
>functions of type Test that can act on a const object are only const
>member functions. This applies of course to overloaded operators too
>since they are member functions themselves (well, when you define them
>as member functions). Do not forget to always declare all the
>"read-only" member functions as const.
>You can perform some magic on const objects using the mutable keyword,
>but i do not think you have reached that level of consciousness yet. :)
>
>
No probably not. However, I've got enough to get me going for now. 8-)
Thanks for the explanation. const for const... Another rule to tag on
to using static members for
callbacks.
>Another interesting thing is that member functions of an object can
>access the private part of objects of the same type.
>
>
>So instead of that:
>
>
>
>>// Operator =
>>Test& Test::operator=(const Test& Test2){
>> data = Test2.getData();
>> data2 = Test2.getData2();
>>
>> return *this;
>>
>>
>
>
>you can do directly that:
>
>
>// Operator =
>Test& Test::operator=(const Test& Test2){
> data = Test2.data;
> data2 = Test2.data2;
>
> return *this;
>}
>
>
True. The only thing I don't like about that is that any validation
I've put
in place doesn't get triggered. I know by that stage in the game that
everything should be okay... but if there are some triggers (like logging,
computation, etc.... I'd lose them). I mean, I could use an initializer
list
too, right? (That always seemed counter-intuitive to me though...
Decreases legibility, unless you're used to it... and same problem as
above...).
Now, speaking of class members, how would you persist state?
In VB (the realm I come from... well, there was Pascal those many
years ago 8-), I would use a Type (read struct) to hold my data.
This allows for quick memory copies to restore defaults/back out
changes... In C++ I can also see it making serialization a little
easier (convert to a char array/string and dump to disk).
Any thoughts on alternative measures to accomplish the same?
(I'm playing with a few projects that might make use of something
like this, but want to make sure that I'm not starting off on the
wrong foot...)
>Keep coding,
>
>
I will. 8-)
|
|
From: Abhijit S. <mu...@gm...> - 2002-07-21 09:11:51
|
> Now, speaking of class members, how would you persist state?
>
> In VB (the realm I come from... well, there was Pascal those many
> years ago 8-), I would use a Type (read struct) to hold my data.
> This allows for quick memory copies to restore defaults/back out
> changes... In C++ I can also see it making serialization a little
> easier (convert to a char array/string and dump to disk).
This isn't always portable, since many compilers use memory alignment to
optimize access... Consider this:
struct foo
{
char bar; // sizeof(char) is 1
int tender; // sizeof(int) is 4
};
sizeof(foo) may not be 5. By default, in most 32-bit optimizing compilers
(including MingW and BC), it'll be 8, since all members are aligned on
dword-boundaries. So if you try to read in the struct using a version of the
program which has been compiled without this optimization, you won't get
what you expected. Neither will your son, when he tries reading it in from a
64-bit compiled program. A more portable way to persist is methods such as
saveToDisk() and loadFromDisk(), which read and write each member. This way
you can also change the read/write method to suit the platform... on
Windows, it can use the registry, on Linux the home dir, on DOS a config
file, etc. You could also interface to classes like FooWriter and FooReader,
to which you can pass the struct/class as an argument.
Hope this helps.
|
|
From: Matthew H. <mhi...@sy...> - 2002-07-22 21:37:21
|
Hello, Abhijit Shylanath wrote: >>Now, speaking of class members, how would you persist state? >> >>In VB (the realm I come from... well, there was Pascal those many >>years ago 8-), I would use a Type (read struct) to hold my data. >>This allows for quick memory copies to restore defaults/back out >>changes... In C++ I can also see it making serialization a little >>easier (convert to a char array/string and dump to disk). >> >> > >This isn't always portable, since many compilers use memory alignment to >optimize access... Consider this: > > Yeah, I'd forgotten about that. I don't worry about portability that much (my primary language being proprietary). Time to change my thinking. But, is it safe to say that everything should be okay if this methodolgy is used for in-memory state maintenance? (Unless I start sharing memory across platforms, I suppose... which isn't extremely likely to happen...8-) >64-bit compiled program. A more portable way to persist is methods such as >saveToDisk() and loadFromDisk(), which read and write each member. This way >you can also change the read/write method to suit the platform... on >Windows, it can use the registry, on Linux the home dir, on DOS a config >file, etc. You could also interface to classes like FooWriter and FooReader, >to which you can pass the struct/class as an argument. > > Use conditional compilation? (#ifdef, etc.) How worried are people about bit problems (i.e. endian-ness cross platform, like Intel to PowerPC). I'd never really stopped to think about it until it came up ... I forget where now, but it was an interesting point. >Hope this helps. > > Yup. My favourite part of lists like this is to throw something out and see how the community at large responds. It usually points out weaknesses, and alternatives. It's always good! 8-) Thanks! |
|
From: Ioannis V. <no...@ho...> - 2002-07-23 11:47:07
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Matthew Hickson > Sent: Tuesday, July 23, 2002 12:39 AM > To: Dev-C++ Mailing List > Subject: Re: [Dev-C++] Copy Constructors and Overloaded > Assignment Operators > > Yeah, I'd forgotten about that. > > I don't worry about portability that much (my primary language being > proprietary). Time > to change my thinking. > > But, is it safe to say that everything should be okay if this > methodolgy > is used for > in-memory state maintenance? You can store data in files in a portable way using text mode (which occupies much space). If you store in binary mode the file is system dependent, that is that the same program compiled in a different compiler (or even a different version of the same compiler) is not guaranteed to read the data properly. I do not know if it is safe when you use the Win32 API. Are they the same funtions precompiled for all compilers in a dll, or every compiler provides its own version of Win32 API? Anyone who knows please inform us. I am studying .NET, and in .NET the same dll is provided (mscorlib.dll) for every compiler. I guess the same is true for Win32 API. But even if Win32 API facilities are the same for every Windows compiler, the binary file is not portable to other OSes. But the text is (that's why HTML, etc are text). But why use files in the first place. I think it is more convenient (and time efficient) to use "roll-back" variables where you will store the previous values. > Use conditional compilation? (#ifdef, etc.) The ANSI C++ file facilities are enough. > How worried are people about bit problems (i.e. endian-ness cross > platform, like Intel to PowerPC). > > I'd never really stopped to think about it until it came up > ... I forget > where now, but it was an interesting point. > > > My favourite part of lists like this is to throw something > out and see > how the community at large > responds. It usually points out weaknesses, and alternatives. It's > always good! 8-) In summary if you want to use (system-dependent) binary files use the ANSII C++ provided facilities. The code will be portable (compile everywhere but by definition binary files are not portable). Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Abhijit S. <mu...@gm...> - 2002-07-25 18:00:42
|
> But, is it safe to say that everything should be okay if this methodolgy
> is used for
> in-memory state maintenance?
I guess so. But I'm still more comfortable having the class take over the
reins. This way you can take care of polymorphism and other such big words.
> >64-bit compiled program. A more portable way to persist is methods such
as
> >saveToDisk() and loadFromDisk(), which read and write each member. This
way
> >you can also change the read/write method to suit the platform... on
> >Windows, it can use the registry, on Linux the home dir, on DOS a config
> >file, etc. You could also interface to classes like FooWriter and
FooReader,
> >to which you can pass the struct/class as an argument.
> >
> >
> Use conditional compilation? (#ifdef, etc.)
You could do that, or you could have different makefiles for different
platforms using the appropriate files.
> How worried are people about bit problems (i.e. endian-ness cross
> platform, like Intel to PowerPC).
>
> I'd never really stopped to think about it until it came up ... I forget
> where now, but it was an interesting point.
I don't think this is much of an issue unless you're doing some
bit-twiddling. In which case it would be safest to store the bit-stuff in a
class which can handle the endian-ness itself. I'm not aware of any #defines
for endian-ness of the current platform. I think you can do a run-time check
like this:
if((unsigned)0x01 >> 1)
// LSB
else
// MSB
|
|
From: Ioannis V. <no...@ho...> - 2002-07-21 10:12:32
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Matthew Hickson > Sent: Sunday, July 21, 2002 2:43 AM > To: 'Dev-C++ Mailing List' > Subject: Re: [Dev-C++] Copy Constructors and Overloaded > Assignment Operators > > Another rule > to tag on > to using static members for > callbacks. What do you mean with that? > Now, speaking of class members, how would you persist state? > > In VB (the realm I come from... well, there was Pascal those many > years ago 8-), I would use a Type (read struct) to hold my data. > This allows for quick memory copies to restore defaults/back out > changes... In C++ I can also see it making serialization a little > easier (convert to a char array/string and dump to disk). > > Any thoughts on alternative measures to accomplish the same? > > (I'm playing with a few projects that might make use of something > like this, but want to make sure that I'm not starting off on the > wrong foot...) Well i guess you can use a reset() member function with no values stored in disk. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Matthew H. <mhi...@sy...> - 2002-07-22 21:47:33
|
Hello, >> Another rule >>to tag on >>to using static members for >>callbacks. >> >> >What do you mean with that? > > As I understand it... callback (particularly in Windows, but other UI toolkits aswell) need to be static class members. It pertains to the implied "this" that is passed to non-static members. Causes a world of difficulty as I understand it. Still trying to figure out some of the techniques for circumventing this. (Not fond of "thunking". How are other people accomplishing this? I've checked out the Reliable Software (?) methodolgy, but it seems a little on the fence between OOP and procedural programming...) >Well i guess you can use a reset() member function with no values stored >in disk. > > True. However, I'd be aiming to restore to a previous state... not necessarily a "blank" initial state. To that end, I'd want to capture a state... and then update it (as changes were accepted by the end user), but allow a fallback to a previous state. The only other... seemingly true OOP solution I see is to have a property method that retains the previous value (saw something like this mentioned in a rogue-like game development newgroup). The only problem being is that it creates a ton of member functions for maintenance. I like simplicity and conciseness in code. Too much code, or too complex code, and it's just a pain to maintain. I'm still experimenting. When I get something worth posting, I'll put it out for public consumption/review 8-). |
|
From: Ioannis V. <no...@ho...> - 2002-07-25 21:42:08
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Matthew Hickson > Sent: Tuesday, July 23, 2002 12:50 AM > To: 'Dev-C++ Mailing List' > Subject: Re: [Dev-C++] Copy Constructors and Overloaded > Assignment Operators > > > Hello, > > As I understand it... callback (particularly in Windows, but other UI > toolkits aswell) > need to be static class members. It pertains to the implied > "this" that > is passed to > non-static members. Causes a world of difficulty as I understand it. C++ is the child of gods. It can't be wrong. :) static members are intended for class-wide operations. > >Well i guess you can use a reset() member function with no > values stored > >in disk. > > > > > True. However, I'd be aiming to restore to a previous state... not > necessarily a "blank" initial state. Well you can create double data members, one for the previous state and one for the current state. > > To that end, I'd want to capture a state... and then update it (as > changes were accepted by the end > user), but allow a fallback to a previous state. The only other... > seemingly true OOP solution I see > is to have a property method that retains the previous value (saw > something like this mentioned in > a rogue-like game development newgroup). The only problem > being is that > it creates a ton of > member functions for maintenance. Why. > I like simplicity and conciseness in code. Too much code, or too > complex code, and it's just a > pain to maintain. You can create backup data members. The space cost can't be that large. Of course you can store everything in files, but that implies time cost. Obviously you have to make a trade off between run-time cost and memory space cost. This is not an OO problem not a C++ problem. I did not however understand why do you want to access normal data members through static member functions. If the backup values are the same for all objects you can create static data members and access them through usual member functions if you wish. That static-members issue of yours confused me. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: <h.r...@gm...> - 2002-07-25 23:09:52
|
Hi all,
I always get a access violation ( access at 0x00000000) at the first getline
command in the following codesnip. Has someone a explanition for this ?
Thanks in advance.
greetings
Horst
codesnip:
[...]
bool isLine2Skip(const string& s) {
return ( (s[0] == ';') || // Comment
(s[0] == ' ') || // Space
s.empty() ); // Empty String
} // bool isLine2Skip
bool ReadDataFile(const string& s)
{
try {
ifstream in(s.c_str());
if (!in) throw ERR_FILE_OPEN;
string line;
do {
getline(in, line);
} while (isLine2Skip(line));
pf.MeanS = atof(line.c_str());
[...]
--
Horst Rößner
Postf. 1802
52205 Stolberg
ICQ ID #74808448
h.r...@gm...
h.g...@t-...
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
|
|
From: Carlos d. M. <cg...@wo...> - 2002-07-26 11:47:34
|
The function is getline(buffer, number of chars);
You have getline(variable I don't see where it comes from, string), but t=
hen it
should say implicit declaration of function, expected getline(char*,int)
Did you overloaded it? If so, the error shall be inthe overloading code.
In bastring is a definition of getline (istream&, basic_string <charT, tr=
aits,
Allocator>&, charT delim =3D '\n'); but this has three parameters.
h.r...@gm... escribi=F3:
> Hi all,
>
> I always get a access violation ( access at 0x00000000) at the first ge=
tline
> command in the following codesnip. Has someone a explanition for this=
?
> Thanks in advance.
>
> greetings
> Horst
>
> codesnip:
> [...]
> bool isLine2Skip(const string& s) {
> return ( (s[0] =3D=3D ';') || // Comment
> (s[0] =3D=3D ' ') || // Space
> s.empty() ); // Empty String
> } // bool isLine2Skip
>
> bool ReadDataFile(const string& s)
> {
> try {
> ifstream in(s.c_str());
> if (!in) throw ERR_FILE_OPEN;
>
> string line;
>
> do {
> getline(in, line);
> } while (isLine2Skip(line));
> pf.MeanS =3D atof(line.c_str());
>
> [...]
>
> --
> Horst R=F6=DFner
> Postf. 1802
> 52205 Stolberg
>
> ICQ ID #74808448
> h.r...@gm...
> h.g...@t-...
>
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>
> -------------------------------------------------------
> This sf.net email is sponsored by: Jabber - The world's fastest growing
> real-time communications platform! Don't just IM. Build it in!
> http://www.jabber.com/osdn/xim
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Abhijit S. <mu...@gm...> - 2002-07-26 20:08:52
|
[Today...] > That static-members issue of yours confused me. [...much, much long ago, in a land far, far away...] > Another rule > to tag on > to using static members for > callbacks. [... same land, somewhere between the two...] > I am facing a tricky problem. I have defined a class, > in which there are few funtions written for > implementing multithreading. I have a funtion named > "createThreads_()", which creates few threads. There > is another function declared in the class, "DWORD > WINAPI threadEntry_(LPVOID)". This function pointer > has been passed in the CREATETHREAD(..) call, which is > being raised as an error in VC++ compier. > It gives the error like, blah > If I use any external function Thread Function(making > it as friend to the class) then compilation is > through, WHICH IS AS EXPECTED. > Similarly, if I make the "threadEntry_(..)" in class > as STATIC and use it in CREATETHREAD(..) call then > also compilation is through. But making STATIC wont > serve my purpose. > I can go ahead with using external function by making > int as friend to the class. [... back to right now...] Okay... putting eleventeen and twenty kazillion together... it seems you cannot callback to non-static member functions (i.e., you cannot have a function pointer pointing to a non-static method). I tried creating a class to test this, and I discovered that it's true... why? I tried callback = this->internal, testclass::internal, this::internal... yup, I got pret-ty desparate. I also tried casting the method, using type-casting (C-style), static_cast and dynamic_cast to a pointer, but it doesn't work. I get an error about converting to a pointer and compilation stops. [... back to the day I first rode a bike... hey, it's *my* post.] |
|
From: Matthew H. <mhi...@sy...> - 2002-07-26 22:26:43
|
>
>
>I tried creating a class to test this, and I discovered that it's true...
>why?
>
>I tried callback = this->internal, testclass::internal, this::internal...
>yup, I got pret-ty desparate.
>
>I also tried casting the method, using type-casting (C-style), static_cast
>and dynamic_cast to a pointer, but it doesn't work. I get an error about
>converting to a pointer and compilation stops.
>
>
>
I'm gathering that you are still looking to do this???
Anyhow, here's some pointers that may be of assistance. (If I
figure anything out... it's yours! 8-)
{Watch out for wordwrap... hey, it could happen...}
http://www.function-pointer.org/CCPP/callback/callback.html
http://cscene.org/topics/misc/cs7-04.xml.html
http://gethelp.devx.com/techtips/cpp_pro/10min/10min0800.asp
Those should get you started.
|
|
From: Ioannis V. <no...@ho...> - 2002-07-27 03:58:16
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Abhijit Shylanath
> Sent: Friday, July 26, 2002 11:08 PM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] Static members for callbacks
>
>
> [... back to right now...]
>
> Okay... putting eleventeen and twenty kazillion together...
> it seems you
> cannot callback to non-static member functions (i.e., you
> cannot have a
> function pointer pointing to a non-static method).
Ok.. It seems i confused subjects. I was thinking that we were talking
about some graphics classes but anyway i am reading like crazy these
days C++ and .NET and there may be some lost clusters somewhere. :)
You can have a function pointer to point to some member functions. But a
non-static member function is not a regular function, that's why we use
special-kind of pointers (a static function on the other hand is a
regular function).
#include <iostream>
int main()
{
class A
{
public:
void something() { std::cout<<"Hello, new world!\n"; }
}a;
void (A::*pf)()=&A::something;
(a.*pf)();
}
> I tried creating a class to test this, and I discovered that
> it's true...
> why?
>
> I tried callback = this->internal, testclass::internal,
> this::internal...
> yup, I got pret-ty desparate.
>
> I also tried casting the method, using type-casting
> (C-style), static_cast
> and dynamic_cast to a pointer, but it doesn't work. I get an
> error about
> converting to a pointer and compilation stops.
>
> [... back to the day I first rode a bike... hey, it's *my* post.]
Well if i understood well your problem was that you did not know how to
define a pointer to member function. Tell me if your problem was solved.
Keep coding,
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Abhijit S. <mu...@gm...> - 2002-07-27 09:02:07
|
> You can have a function pointer to point to some member functions. But a
> non-static member function is not a regular function, that's why we use
> special-kind of pointers (a static function on the other hand is a
> regular function).
>
> #include <iostream>
>
>
> int main()
> {
> class A
> {
> public:
> void something() { std::cout<<"Hello, new world!\n"; }
> }a;
>
> void (A::*pf)()=&A::something;
Okay, so this is how it's done... thanks. But this means that you can't use
non-static methods for external callbacks (like Windows') directly.
Waitaminit... in what you've done above, aren't all objects' 'pf's set to
A::something? What if I want one object's pf pointing to something, and
another object's pf poiting to something_else?
|
|
From: Ioannis V. <no...@ho...> - 2002-07-27 13:21:09
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Abhijit Shylanath
> Sent: Saturday, July 27, 2002 11:26 AM
> To: Dev-C++ Mailing List
> Subject: Re: [Dev-C++] Static members for callbacks
>
>
> > #include <iostream>
> >
> >
> > int main()
> > {
> > class A
> > {
> > public:
> > void something() { std::cout<<"Hello, new world!\n"; }
> > }a;
> >
> > void (A::*pf)()=&A::something;
>
> Okay, so this is how it's done... thanks. But this means that
> you can't use
> non-static methods for external callbacks (like Windows') directly.
Can you explain the above?
> Waitaminit... in what you've done above, aren't all objects'
> 'pf's set to
> A::something? What if I want one object's pf pointing to
> something, and
> another object's pf poiting to something_else?
Contrary to what you may thing a member function is unique for every
class. The only difference is that a *this pointer is passed to it in
addition to the other arguments and the compiler makes some additional
magic so as to behave as if there is one for each object (it uses *this
to permit you acccess the private members directly in the style
void A::something(void)
{
x++;
}
where x is a private member.
So if you have the above member function you can use void (A::*pf)() to
point to it and it will act the same "indepedently" on every object of
the class where it is called.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Abhijit S. <mu...@gm...> - 2002-07-28 20:43:38
|
> > Okay, so this is how it's done... thanks. But this means that > > you can't use > > non-static methods for external callbacks (like Windows') directly. > > > Can you explain the above? You can't use non-static methods for windows callbacks (like in CreateThread(), SetWindowsHookEx()) which need you to suppply a call-back function. |
|
From: Ioannis V. <no...@ho...> - 2002-07-28 21:09:20
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Abhijit Shylanath > Sent: Sunday, July 28, 2002 11:15 AM > To: Dev-C++ Mailing List > Subject: Re: [Dev-C++] Static members for callbacks > > > > > Okay, so this is how it's done... thanks. But this means that > > > you can't use > > > non-static methods for external callbacks (like Windows') > directly. > > > > > > Can you explain the above? > > You can't use non-static methods for windows callbacks (like in > CreateThread(), SetWindowsHookEx()) which need you to suppply > a call-back > function. This is too Win32 to me. What do you mean by call-back function. Can you provide a small concrete example? I am learning .NET myself which is c00l and fully OO (and very easy) and it has nothing to do with Win32 but that's another story. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Abhijit S. <mu...@gm...> - 2002-07-29 06:51:37
|
> > You can't use non-static methods for windows callbacks (like in
> > CreateThread(), SetWindowsHookEx()) which need you to suppply
> > a call-back
> > function.
>
>
> This is too Win32 to me. What do you mean by call-back function. Can you
> provide a small concrete example?
Basically, typedef function_pointer call_back;
For example, in CreateThread(), the args are:
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, // address of thread security
attributes
DWORD dwStackSize, // initial thread stack size, in bytes
LPTHREAD_START_ROUTINE lpStartAddress, // address of thread function
LPVOID lpParameter, // argument for new thread
DWORD dwCreationFlags, // creation flags
LPDWORD lpThreadId // address of returned thread identifier
);
Here, LPTHREAD_START_ROUTINE should be a function pointer to a 32-bit
returning (void *) accepting function, as in
DWORD my_thread_proc(void *some_arg);
where DWORD is, on Win32, unsigned long.
PS: Sorry for a double-post of the previous message. I thought it hadn't got
through,
so I reposted it, after which I received the original message... I guess the
list server is acting up...
|
|
From: Ioannis V. <no...@ho...> - 2002-07-29 07:34:12
|
> -----Original Message----- > From: Abhijit Shylanath [mailto:mu...@gm...] > Sent: Monday, July 29, 2002 9:50 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: Re: [Dev-C++] Static members for callbacks > > > > > You can't use non-static methods for windows callbacks (like in > > > CreateThread(), SetWindowsHookEx()) which need you to suppply > > > a call-back > > > function. > > > > > > This is too Win32 to me. What do you mean by call-back > function. Can you > > provide a small concrete example? > > > Basically, typedef function_pointer call_back; > > For example, in CreateThread(), the args are: > > HANDLE CreateThread( > LPSECURITY_ATTRIBUTES lpThreadAttributes, // address of > thread security > attributes > DWORD dwStackSize, // initial thread stack size, in bytes > LPTHREAD_START_ROUTINE lpStartAddress, // address of > thread function > LPVOID lpParameter, // argument for new thread > DWORD dwCreationFlags, // creation flags > LPDWORD lpThreadId // address of returned thread identifier > ); > > Here, LPTHREAD_START_ROUTINE should be a function pointer to a 32-bit > returning (void *) accepting function, as in > > DWORD my_thread_proc(void *some_arg); > > where DWORD is, on Win32, unsigned long. Ok then you can use a regular function to call the appropriate member function. This regular function will accept also your object as a parameter. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |