Ok fine, but i havent said any time "i dont need to read this or that or go here or there and no one has responsiblity to tell me what should i do" . If someone advice me then i surely read that book and go to that side, just like Paul advice me to read one good book of STL.Quote:
Originally posted by AnthonyMai
you do not know what you think you know.
And now only one program related to your questions of static. Hope it shows what i want to say.
I used this type of techniques lots of time when using threading in VC where the thread function need void pointer and i pass the address of the class and then access other data from that pointer. Of course that thread function is static in my that class, because it hase to be.Code:#include <iostream>
using namespace std;
class C
{
public:
static void StaticFun(C* pC)
{
pC->NonStaticFun();
}
void NonStaticFun()
{
cout << "Non Static Fun" << endl;
}
};
int main()
{
C objC;
C::StaticFun(&objC);
return 0;
}
Thats what i want to said, this code runs on VC6 because i explore the memory layout of VC6, but it doesnt mean it runs on other compiler. Why? Because it is not standard, and if it is standard then it should be run on every plateform. And that artical disuss ATL not C++ so i discuss those techniques which ATL use internally.Quote:
Originally posted by AnthonyMai
You are lucky to have it work on VC6 because in your virtual function you are not touching any class data member.
Finally you accept this, thats what i want to say, v-table is not standard.Quote:
Originally posted by AnthonyMai
There CAN be different ways of v-table implementation.
Excuse me, v-ptr is exists with class data. (In case of VC and most of other compiler, it is not standard too). v-table is not exists with class data. I think again take a look at Part 1 and Part 2 where i show this with small program on VC.Quote:
Originally posted by AnthonyMai
no matter how v-table is implemented, it would have to be put into the same chunk of memory where all other class data members sit
OK, but what about output of this program?Quote:
Originally posted by AnthonyMai
There is just no reasonable way to put data pertaining to a class's state into two different chunks of memory. And I have not seen any implementation does it in such un-thinkable way.
It should be 6, but in VC and on gcc 2.96 Rad Hat Linux 7.0 it is 12. Now change it little bit.Code:#include <iostream>
using namespace std;
class C
{
char ch1;
int i;
char ch2;
};
int main()
{
cout << sizeof(C) << endl;
return 0;
}
I m sure you know what is pragma pack.Code:#include <iostream>
using namespace std;
#pragma pack(1)
class C
{
char ch1;
int i;
char ch2;
};
int main()
{
cout << sizeof(C) << endl;
return 0;
}
I still dont know why you compare algorithm with specification. qsort is algorithm and std::sort is an specification. And if you really want to compare algorithm analysis take a look at
The Art of Computer programming vol 3
by Doneld E Knuth
It seem you consider all
Graham
Paul McKenzie
jfaust
Philip Nicoletti
Ruslan Abdikeev
of them wrong although they give so solid logical reasong. Or may be you want to create the longest thread on codeguru. Ok if all of us are wrong then why not directly mail to your code to Bjarne Stroustrup, scott Meyrs, Herb Sutter, Stan Lippman or Andrew Koenig, Douglas Schmidt, Barbra Moo, Andrei Alexandrescu, Rob Murrey etc.
At least write and artical on CUJ on this, and gain fame.
Hope to here yoo on comp.lang.c++, comp.lang.c++.moderated and CUJ soon.
