|
The reason this is so is that method does not know anything about the instance that calls it. The instance pointer (this) is resolved at the moment of method call. This:
C c;<br />
c.method();
is executed using always one and the same address of the method but the class instance pointer ( this-> ) is passed for example as the first hidden parameter (which is hidden from us) like this
method(&c)
or the instance pointer (&c) is moved into ECX register first and then method() is called where each this-> is then referred by the content of ECX.
You can't avoid this problem even with boost or any other library.
|
|
|
|
|
If you are ready to make a slight design change this is what you can do and to get something fairly useful
class T
{
public:
virtual void run() = 0;
virtual void run1() = 0;
};
class A : public T
{
public:
void run(){
};
void run1(){
};
};
class F : public T
{
public:
void run(){
};
void run1(){
};
};
class R{
public:
typedef void (T::*Method)();
Method onClick;
void Do(T* t)
{
(t->*onClick)();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A a;
F f;
R r;
r.onClick = &T::run;
r.Do(&a);
r.Do(&f);
r.onClick = &T::run1;
r.Do(&a);
r.Do(&f);
...
modified on Monday, March 2, 2009 5:57 PM
|
|
|
|
|
|
Sounds like a homework problem.
Anyway, could you describe exactly what the difference between the two formats is?
|
|
|
|
|
You need to state exactly what type of format or organising structure you are trying to acheive.
|
|
|
|
|
Are you trying to just get rid of the duplicated record?
|
|
|
|
|
It's my problem man.I don't what rid problem and what he want to do..If you have some idia then plz help me
|
|
|
|
|
i need remove duplicate values..
|
|
|
|
|
You can use "std::unique" algo, but you will have to design your own class with overloads to support it.
Example[^]
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Then in any environment, you need to qualify what you wish to discard.
You need to place a field (that you specify) into a list box and disallow
the duplication of a matching field. If the field or database.component is
new then allow the record to be copied to a new file.
At the end (after testing) simply replace your old file with the new one.
I'm assuming your running a few thousand records.
|
|
|
|
|
Ric Ashton wrote: I'm assuming your running a few thousand records.
Don't be so generous. This is obviously a homework assignment.
|
|
|
|
|
1- create a structure (or class) that contains the fields for each record ; create/use a collection that holds your records
2- in a loop :
3- read one line of the file, knowing that you know the format, you can skip unwanted lines.
4- skip line if unwanted; if line contains (is?) "============" and it's the first one, then you know it's a
new record.
5- read the next few lines to fill a record.
6- look in your collection to see if new record is already there; if it's not there, add it to your collection.
7- once you've read all the lines,
8- write back the data line-by-line in a new file.
(steps 5,6 can be optimized to not have to create a new record until you've find if the item is not in the collection).
This signature was proudly tested on animals.
|
|
|
|
|
Thanks sir your logic is to much sound.Can you give me some dummy code.Plz help me
|
|
|
|
|
I will not give you code (dummy or not); I want you to try to come up with a solution based on the suggestions we've given you.
Once you've tried one, two, or even more solutions to your problem (which sounds like a homework), and you still
have problems, then we will gladly be of help of precise problems you can still have.
It can be also easier to ask questions to your teachers and/or teaching assistants and/or computer lab assistants;
or even fellow students.
This signature was proudly tested on animals.
|
|
|
|
|
The first order of business would be to read the data into some sort of data structure. Until you can get that far, eliminating duplicates is irrelevant.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Given the struct declaration thus:
struct TestStruct
{
CObject obj[ 20 ];
};
If I say,
TestStruct *ts = new TestStruct;
Does the CRT call the constructors for any of the CObject's, either all of them, or just the first one in the array?
And does the same answer apply to calling the destructors when I delete ts ?
|
|
|
|
|
All 20 CObject default constructors will be called on creation.
Destructors will also be called on destruction.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the reply. I am surprised, actually. I did not expect that all of them would be called.
|
|
|
|
|
They are all allocated on the stack & so gets cleaned automatically. You are almost nearly talking about something like this :
struct TestStruct
{
CObject* pObj;
TestStruct()
{
pObj = new CObject[20];
}
};
Then in the dtor you'll have to manually delete all the cobjects.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Don't confuse it all.
Assume we have
struct TestStruct{
CObject obj[ 20 ];
};
{
TestStruct ts;
}
{
TestStruct *ts = new TestStruct;
delete ts;
}
{
TestStruct *ts = new TestStruct;
}
|
|
|
|
|
Thanks for clearing that up.
I was confused as well.
|
|
|
|
|
I think I'm not confused.
Here[^]
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
struct TestStruct{
CObject obj[ 20 ];
};
Didn't you notice I changed my example to
struct TestStruct{
CObject* pobj;
TestStruct()
{
pObj = new CObject[20];
}
};
?
I was trying to give an example where the destructors of the CObjects wouldn't be called. What am I confusing here? Whatever may be the creating type of the TestStruct object, heap or stack, here in my example, it's going to create all the CObjects in heap.
I'll explain you better. Suppose Now you create an object of TestStruct:
TestStruct obj;
So in the destructor we have to manually delete them all.
~TestStruct()
{
delete[] pObj;
}
That's what I explained. May be you didn't get my context.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Easy, man! We are just talking here.
Just to be safe, I explained it all relevant to the question.
From your initial post, it was not totally clear that you meant this what you have shown here, and it is a different example from what was asked, so I just wrote it all out using the same code pattern from the initial question to avoid any possible confusion, because everything is fine as long as the person who asked the question got the right understanding not you or me.
|
|
|
|
|