Board index » cppbuilder » FYI

FYI


2003-07-17 12:34:03 PM
cppbuilder108
I tried what you said, but had problems, but it basically gave
me the right direction;
template <class Object>class Pointer;
template <class Object>class VPointer
{
public:
VPointer();
int (Pointer<Object>:: *PInt)();
//...
};
template <class Object>class Pointer
{
private:
void *Point;
//...
public:
int PInt()
{
return reinterpret_cast <int>(Point);
}
//...
};
template <class Object>VPointer<Object>::VPointer()
{
PInt = &Pointer<Object>::PInt;
//...
};
class SimpleLock : public Pointer <SimpleLock>
{ //...
bool Lock(int *pPID)
{ //...
cout << (this->*THIS_.PInt)(); //...
return true;
}
};
All of this compiled fine. Thanks
 
 

Re:FYI

"ta0kira" < XXXX@XXXXX.COM >writes:
Quote
template <class Object>VPointer<Object>::VPointer()
{
PInt = &Pointer<Object>::PInt;
//...
};
The semicolon on the last line is a syntax error (although I wouldn't know
of a compiler that rejects it).
Why don't you initialize members in the member initializer list?
 

Re:FYI

Ok, I have created some test classes and a test function:
template <class Object>class CLASS1;
template <class Object>class CLASS2
{
public:
CLASS2();
void SET(CLASS1<Object>*SETME);
int (CLASS1<Object>:: *ONE)();
int (CLASS1<Object>:: *TWO)();
};
template <class Object>class CLASS1
{
private:
int NUMBER1;
protected:
int NUMBER2;
public:
CLASS1()
{srand(time(NULL) + rand()); NUMBER1 = rand(); NUMBER2 = rand();}
int ONE();
int TWO();
};
template <class Object>int CLASS1<Object>::ONE()
{return NUMBER1;};
template <class Object>int CLASS1<Object>::TWO()
{return NUMBER2;};
template <class Object>CLASS2<Object>::CLASS2()
{
ONE = &CLASS1<Object>::ONE;
TWO = &CLASS1<Object>::TWO;
};
class TESTER1 : public CLASS1<TESTER1>
{
public:
CLASS2 <TESTER1>ME;
GET1() {return (this->*ME.ONE)();}
ACTUAL1() {return CLASS1<TESTER1>::ONE();}
GET2() {return (this->*ME.TWO)();}
ACTUAL2() {return CLASS1<TESTER1>::TWO();}
};
class TESTER2 : public TESTER1, CLASS1<TESTER2>
{
public:
CLASS2 <TESTER2>ME;
GET1() {return (this->*ME.ONE)();}
ACTUAL1() {return CLASS1<TESTER2>::ONE();}
GET2() {return (this->*ME.TWO)();}
ACTUAL2() {return CLASS1<TESTER2>::TWO();}
};
void RUNTEST()
{
TESTER1 TEST1;
TESTER2 TEST2;
cout << "TEST1: (->1) " << TEST1.GET1() << ", (->2) " << TEST1.GET2()
<< ", (*1) " << TEST1.ME.ONE << ", (*2) " << TEST1.ME.TWO
<< endl << "ACTUAL1: (1) " << TEST1.ACTUAL1() << ", (2) " << TEST1.ACTUAL2()
<< endl;
cin.get();
cout << "TEST2: (->1) " << TEST2.GET1() << ", (->2) " << TEST2.GET2()
<< ", (*1) " << TEST2.ME.ONE << ", (*2) " << TEST2.ME.TWO
<< endl << "ACTUAL2: (1) " << TEST2.ACTUAL1() << ", (2) " << TEST2.ACTUAL2()
<< endl;
cin.get();
};
When I use RUNTEST(), everything reflects correctly except the
calls to TEST1.ME.ONE etc. all return 1. I know this is the
incorrect syntax to call them, but when I use * or ->or *()
and any other combination you could think of I get
"call to a nonfunction"
"incorrect use of pointer"
"undefined symbol"
"pointer to structure needed on left side of ->or ->*"
I cannot seem to get access to the CLASS2 from outside of the
class structure.
I tried using this:
template <class Object>CLASS2<Object>::ONE
: &CLASS1<Object>::ONE;
template <class Object>CLASS2<Object>::TWO
: &CLASS1<Object>::TWO;
instead of the default constructor, but I get
"multiple declaration"
I also tried to // the declaration of ONE and TWO in the
declaration of template <class Object>class CLASS2, but I get
"ONE is not a member of CLASS2"
I guess I am half way there. I have access from inside the
class, now I need it from outside the class, which is more the
point of the whole thing. Any suggestions? Thanks
ta0kira
 

{smallsort}

Re:FYI

"ta0kira" < XXXX@XXXXX.COM >writes:
Quote
Ok, I have created some test classes and a test function:
I have tried compiling them, but there are some things missing:
- #includes
- cout, cin and endl belong to namespace std
- return types:
Quote
class TESTER1 : public CLASS1<TESTER1>
{
public:
CLASS2 <TESTER1>ME;
GET1() {return (this->*ME.ONE)();}
What type does GET1 return?
- the main() function
Please post code that makes it as easy as possible for your audience to
copy&paste&compile it. Thanks!
Quote
When I use RUNTEST(), everything reflects correctly except the
calls to TEST1.ME.ONE etc. all return 1. I know this is the
incorrect syntax to call them, but when I use * or ->or *()
and any other combination you could think of I get
"call to a nonfunction"
"incorrect use of pointer"
"undefined symbol"
"pointer to structure needed on left side of ->or ->*"
TEST1.ME.ONE is a pointer to a member. You have to apply it to the object
whose member you want to access:
(TEST1.*TEST1.ME.ONE)()
If you change the derivation of TESTER2 from CLASS1<TESTER2>from private to
public, by doing
class TESTER2 : public TESTER1, public CLASS1<TESTER2>
(note the 2nd public), this will compile and run:
int main()
{
TESTER1 TEST1;
std::cout << "TEST1: "
<< "(->1) " << TEST1.GET1() << ", "
<< "(->2) " << TEST1.GET2() << ", "
<< "(*1) " << (TEST1.*TEST1.ME.ONE)() << ", "
<< "(*2) " << (TEST1.*TEST1.ME.TWO)() << '\n'
<< "ACTUAL1: "
<< "(1) " << TEST1.ACTUAL1() << ", "
<< "(2) " << TEST1.ACTUAL2() << '\n';
TESTER2 TEST2;
std::cout << "TEST2: "
<< "(->1) " << TEST2.GET1() << ", "
<< "(->2) " << TEST2.GET2() << ", "
<< "(*1) " << (TEST2.*TEST2.ME.ONE)() << ", "
<< "(*2) " << (TEST2.*TEST2.ME.TWO)() << '\n'
<< "ACTUAL2: "
<< "(1) " << TEST2.ACTUAL1() << ", "
<< "(2) " << TEST2.ACTUAL2() << '\n';
}
Quote
I cannot seem to get access to the CLASS2 from outside of the
class structure.

I tried using this:

template <class Object>CLASS2<Object>::ONE
: &CLASS1<Object>::ONE;
Are you trying to initalize CLASS2<Object>::ONE with the address of
CLASS1<Object>::ONE? You best do that in the member initialization list:
template <class Object>
CLASS2<Object>::CLASS2()
: ONE(&CLASS1<Object>::ONE)
, TWO(&CLASS1<Object>::TWO)
{
}
 

Re:FYI

#include <stdlib.h>
#include <time.h>
template <class Object>class CLASS1;
template <class Object>class CLASS2
{
public:
CLASS2();
int (CLASS1<Object>:: *ONE)();
int (CLASS1<Object>:: *TWO)();
};
template <class Object>class CLASS1
{
private:
int NUMBER1;
protected:
int NUMBER2;
public:
CLASS2 <CLASS1 <Object>>ME;
CLASS1()
{srand(time(NULL) + rand()); NUMBER1 = rand(); NUMBER2 = rand();}
int ONE();
int TWO();
};
template <class Object>int CLASS1<Object>::ONE()
{return NUMBER1;}
template <class Object>int CLASS1<Object>::TWO()
{return NUMBER2;}
template <class Object>CLASS2<Object>::CLASS2()
{
ONE = &CLASS1<Object>::ONE;
TWO = &CLASS1<Object>::TWO;
}
class TESTER1 : public CLASS1<TESTER1>
{
public:
CLASS2 <TESTER1>ME;
int GET1() {return (this->*ME.ONE)();}
int ACTUAL1() {return CLASS1<TESTER1>::ONE();}
int GET2() {return (this->*ME.TWO)();}
int ACTUAL2() {return CLASS1<TESTER1>::TWO();}
};
class TESTER2 : public TESTER1, public CLASS1<TESTER2>
{
public:
CLASS2 <TESTER2>ME;
int GET1() {return (this->*ME.ONE)();}
int ACTUAL1() {return CLASS1<TESTER2>::ONE();}
int GET2() {return (this->*ME.TWO)();}
int ACTUAL2() {return CLASS1<TESTER2>::TWO();}
};
void main()
{
TESTER1 TEST1;
TESTER2 TEST2;
cout << "TEST ONE: TESTER1 DERIVED FROM CLASS1. 1= PRIVATE, 2= PROTECTED\n"
<< "ME IS A PUBLIC MEMBER OF TESTER1, WHICH MIRRORS CLASS1<TESTER1>::\n";
cout << "TESTER1 TEST1:\nGET: (->1) " << TEST1.GET1() << ", (->2) " << TEST1.GET2() << endl
<< "TEST1.*TEST1.ME: (*1) " << (TEST1.*TEST1.ME.ONE)() << ", (*2) " << (TEST1.*TEST1.ME.TWO)()
<< endl << "ACTUAL: (1) " << TEST1.ACTUAL1() << ", (2) " << TEST1.ACTUAL2()
<< endl;
cin.get();
cout << "TEST TWO: TESTER2 DERIVED FROM TESTER1 AND CLASS1. 1= PRIVATE, 2= PROTECTED\n"
<< "ME IS A PUBLIC MEMBER OF TESTER1, WHICH MIRRORS CLASS1<TESTER2>::\n";
cout << "TESTER2 TEST2:\nGET: (->1) " << TEST2.GET1() << ", (->2) " << TEST2.GET2() << endl
<< "TEST1.*TEST1.ME: (*1) " << (TEST2.*TEST2.ME.ONE)() << ", (*2) " << (TEST2.*TEST2.ME.TWO)()
<< endl << "ACTUAL: (1) " << TEST2.ACTUAL1() << ", (2) " << TEST2.ACTUAL2()
<< endl;
cin.get();
}
This will run perfectly as I want it to. I am not sure why it
ran without me putting a return type on GET1 and GET2. The
(TEST1.*TEST1.ME.ONE)() was the answer I was looking for. If
you notice on each test, all the 1 vals and all the 2 vals are
the same, which is what I was looking for. Why is the
additional TEST1 needed? Anyway, I will model my classes after
the classes above. Hopefully it will work the same. Thanks
ta0kira
 

Re:FYI

"ta0kira" < XXXX@XXXXX.COM >writes:
Quote
#include <stdlib.h>
#include <time.h>
These aren't the right headers. Please look up in your C++ text book what you
have to #include to be able to use std::cin, std::cout and std::endl. The
textbook probably won't tell you that you also have to #include <ostream>
for operator<< and <istream>for operator>>(for the built-in types).
I haven't seen the need for <stdlib.h>and <time.h>(in current C++, one
would rather write <cstdlib>and <ctime>) in your code.
Quote
void main()
This was only accepted because of a compiler bug. The return type of main()
has to be int.
Quote
This will run perfectly as I want it to. I am not sure why it
ran without me putting a return type on GET1 and GET2.
C used to have so-called "implicit int", i.e. if you didn't mention the
return type in a function declararation, int was assumed. Maybe the compiler
you are using still supports that obsolete feature.
Quote
Why is the additional TEST1 needed?
As I wrote in my last post, TEST1.ME.ONE is simply a pointer to member. Given
an object, it will give back a member of that object.
 

Re:FYI

#include <iostream.h>//For console output
#include <time.h>//For time(NULL)
template <class Object>class CLASS1;
template <class Object>class CLASS2
{
public:
CLASS2();
int (CLASS1<Object>:: *ONE)();
int (CLASS1<Object>:: *TWO)();
};
template <class Object>class CLASS1
{
private:
int NUMBER1;
protected:
int NUMBER2;
public:
CLASS2 <CLASS1 <Object>>ME;
CLASS1()
{srand(time(NULL) + rand()); NUMBER1 = rand(); NUMBER2 = rand();}
int ONE();
int TWO();
};
template <class Object>int CLASS1<Object>::ONE()
{return NUMBER1;}
template <class Object>int CLASS1<Object>::TWO()
{return NUMBER2;}
template <class Object>CLASS2<Object>::CLASS2()
{
ONE = &CLASS1<Object>::ONE;
TWO = &CLASS1<Object>::TWO;
}
class TESTER1 : public CLASS1<TESTER1>
{
public:
CLASS2 <TESTER1>ME;
int GET1() {return (this->*ME.ONE)();}
int ACTUAL1() {return CLASS1<TESTER1>::ONE();}
int GET2() {return (this->*ME.TWO)();}
int ACTUAL2() {return CLASS1<TESTER1>::TWO();}
};
class TESTER2 : public TESTER1, public CLASS1<TESTER2>
{
public:
CLASS2 <TESTER2>ME;
CLASS2 <TESTER1>PARENT;
int GET1() {return (this->*ME.ONE)();}
int PGET1() {return (this->*PARENT.ONE)();}
int ACTUAL1() {return CLASS1<TESTER2>::ONE();}
int PARENT1() {return CLASS1<TESTER1>::ONE();}
int GET2() {return (this->*ME.TWO)();}
int PGET2() {return (this->*PARENT.TWO)();}
int ACTUAL2() {return CLASS1<TESTER2>::TWO();}
int PARENT2() {return CLASS1<TESTER1>::TWO();}
};
int main()
{
TESTER1 TEST1;
TESTER2 TEST2;
cout << "TEST ONE: TESTER1 DERIVED FROM CLASS1. 1= PRIVATE, 2= PROTECTED\n"
<< "ME IS A PUBLIC MEMBER OF TESTER1, WHICH MIRRORS CLASS1<TESTER1>::\n";
cout << "TESTER1 TEST1:\n(this->*ME.ONE)() " << TEST1.GET1() << ", (this->*ME.TWO)() " << TEST1.GET2() << endl
<< "(TEST1.*TEST1.ME.ONE)() " << (TEST1.*TEST1.ME.ONE)() << ", (TEST1.*TEST1.ME.TWO)() " << (TEST1.*TEST1.ME.TWO)()
<< endl << "CLASS1<TESTER1>::ONE() " << TEST1.ACTUAL1() << ", CLASS1<TESTER1>::TWO() " << TEST1.ACTUAL2()
<< endl;
cin.get();
cout << "TEST TWO: TESTER2 DERIVED FROM TESTER1 AND CLASS1. 1= PRIVATE, 2= PROTECTED\n"
<< "ME IS A PUBLIC MEMBER OF TESTER2, WHICH MIRRORS CLASS1<TESTER2>::\n"
<< "PARENT IS A PUBLIC MEMBER OF TESTER, WHICH MIRRORS CLASS1<TESTER1>::\n";
cout << "TESTER2 TEST2:\n(this->*ME.ONE)() " << TEST2.GET1() << ", (this->*ME.TWO)() " << TEST2.GET2() << endl
<< "(TEST2.*TEST2.ME.ONE)() " << (TEST2.*TEST2.ME.ONE)() << ", (TEST2.*TEST2.ME.TWO)() " << (TEST2.*TEST2.ME.TWO)()
<< endl << "CLASS1<TESTER2>::ONE() " << TEST2.ACTUAL1() << ", CLASS1<TESTER2>::TWO() " << TEST2.ACTUAL2()
<< endl << "(TEST2.*TEST2.PARENT.ONE)() " << (TEST2.*TEST2.PARENT.ONE)() << ", (TEST2.*TEST2.PARENT.TWO)() " << (TEST2.*TEST2.PARENT.TWO)()
<< endl << "CLASS1<TESTER1>::ONE() " << TEST2.PARENT1() << ", CLASS1<TESTER1>::TWO() " << TEST2.PARENT2()
<< endl;
cin.get();
}
Notice that the last 2 lines of TEST TWO will be different than
those above them. This was the effect I was trying to get.
Thanks again for the help, and sorry for not posting clear
questions.
ta0kira
 

Re:FYI

List of domain names selling on Ebay
PHILHARMONIC.NET $1,000.00 0 -- 1 0 2d 16h 00m Sell Similar
GETBUILT.COM $1,000.00 0 -- 1 0 6d 09h 16m Sell Similar
HATFIND.COM $1,000.00 0 -- 1 0 8d 01h 34m Sell Similar
MYSUBSCRIBER.COM $1,000.00 0 -- 1 0 9d 05h 53m Sell Similar
SUSHIJOY.COM $1,000.00 0 -- 0 0 2d 02h 22m Sell Similar
SHOWJAM.COM $1,000.00 0 -- 0 0 2d 15h 58m Sell Similar
SUPPLYITALL.COM $1,000.00 0 -- 0 0 2d 16h 01m Sell Similar
CHICAGOMAID.COM $1,000.00 0 -- 0 0 2d 16h 02m Sell Similar
STOCKINGSGIRL.COM $1,000.00 0 -- 0 0 2d 16h 03m Sell Similar
SUPERCREATION.COM $1,000.00 0 -- 0 0 2d 16h 04m Sell Similar
SIMPLYTOWELS.COM $1,000.00 0 -- 0 0 2d 16h 07m Sell Similar
PAYMAILBOX.COM $1,000.00 0 -- 0 0 2d 16h 08m Sell Similar
CHICKWISH.COM $1,000.00 0 -- 0 0 2d 16h 10m Sell Similar
SUPREMEWAREHOUSE.COM $1,000.00 0 -- 0 0 2d 16h 11m Sell Similar
SIGNAPRO.COM $1,000.00 0 -- 0 0 2d 23h 26m Sell Similar
AMERICAHERE.COM $1,000.00 0 -- 0 0 4d 00h 08m Sell Similar
GOODRULES.COM $1,000.00 0 -- 0 0 4d 05h 19m Sell Similar
CHICAGOLOOP.COM $30,000.00 0 -- 0 0 5d 02h 59m Sell Similar
MONEYMAKINGEASY.COM $1,000.00 0 -- 0 0 5d 03h 02m Sell Similar
PIMPLEPASTE.COM $1,000.00 0 -- 0 0 5d 03h 03m Sell Similar
SMSMANIAC.COM $1,000.00 0 -- 0 0 5d 03h 03m Sell Similar
USAPARTIES.COM $1,000.00 0 -- 0 0 6d 09h 12m Sell Similar
HULKOUT.COM $1,000.00 0 -- 0 0 7d 06h 15m Sell Similar
HELPERBOY.COM $1,000.00 0 -- 0 0 7d 20h 47m Sell Similar
HOTMATRIX.COM $500.00 0 -- 0 0 8d 01h 32m Sell Similar
Legend:
Auction Format
Store Inventory Format
Fixed Price Format
Second Chance Offer
Ad Format
Prices of items currently selling are green and bold; those not
currently selling are red. Back to top
Page 1 of 2 Go to page
Previous 1 | 2 Next
About Items I'm Selling
This is your "Items I'm Selling" view. Details about all of
the items you are selling will display here. After an item ends, it will
appear in either your "Items I've Sold" or "Unsold Items" view.
 

Re:FYI

FYI:
I tried a move my core funtions into my COM Obj, which mean I had to now
manually include the nesesary header, since my COM have no Visual control.
I notict that when you #include <IdTCPClient.hpp>, i get error that alot of
variables was decleared early.
on examination i noticed that both the winsock2.h and winsock.h was include
along the IdTCPClient.hpp which is not the case if i had place the control
on the Form directly.
However i worked around it by #define _WINSOCKAPI_ just before #include
<IdTCPClient.hpp>
Am just wondering if I did some wrong along the line or if anybody have
noticed this too.
 

Re:FYI

"Darlington ADIBE" < XXXX@XXXXX.COM >wrote in message
Quote
I notict that when you #include <IdTCPClient.hpp>, i get error
that alot of variables was decleared early. on examination i noticed
that both the winsock2.h and winsock.h was include along the
IdTCPClient.hpp
That is a known issue with Indy. It is more of a Microsoft problem than an
Indy problem, though, because winsock.h and winsock2.h are not compatible
with each other. The VCL uses winsock.h whereas Indy uses winsock2.h
instead.
Gambit
 

Re:FYI

FYI: Matt Jacobs likes the smell of his own ass.
--
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:FYI

Ben Franklin wrote:
Quote
FYI: Matt Jacobs likes the smell of his own ass.
You must be very sharp-eyed person.
MH
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:FYI

Ben Franklin wrote:
Quote
FYI: Matt Jacobs likes the smell of his own ass.
How did you determine this?
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:FYI

Matt Jacobs *likes* the smell of his own ass.
--
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.