473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Templates and Typedefs

here is an example of what im trying to do in the most basic form,

template<class T, class I> class A : public T {

typedef struct {I i; T t;} e;
// functions not that important, not the issue
}

struct {... } typea;
struct {... } typeb;
A<type,int> _a;
A<typea,int> _b;

Problem: when instantiating _b, entry.T is of the form typea
and not typeb. so when i try doing something like
entry.T = (T &)(*this) it produces cannot convert
from typea to typeb and vice versa.
I have also tried just declaring struct e without typedef and the same thing
happens. I think the solution involves the keyword
typename but Im having trouble figureing it out.

If anyone can help id appreciate it. Thanks


Jul 19 '05 #1
6 1500
"dwrayment" <dw*******@rogers.com> wrote...
here is an example of what im trying to do in the most basic form,

template<class T, class I> class A : public T {

typedef struct {I i; T t;} e;
// functions not that important, not the issue
}

struct {... } typea;
struct {... } typeb;
Did you mean to write

struct typea {};
struct typeb {};

???
A<type,int> _a;
What's "type"? Did you mean "typeb"?
A<typea,int> _b;

Problem: when instantiating _b, entry.T is of the form typea
What's "entry"? Did you mean "e"? And there is no e.T. There is
only e.t. Did you mean "e.t" instead of "entry.T"?
and not typeb. so when i try doing something like
entry.T = (T &)(*this) it produces cannot convert
from typea to typeb and vice versa.
Why would you do that?
I have also tried just declaring struct e without typedef and the same thing happens. I think the solution involves the keyword
typename but Im having trouble figureing it out.

If anyone can help id appreciate it. Thanks


You'll have to excuse me, I am trying to get all the ducks in a row
here. What are you trying to do, actually?

This (irrelevant things removed):

template<class T, class I> struct A : public T
{
struct
{
I i;
T t;
} entry;

A() { entry.t = *this; }
};

struct typea {};

int main()
{
A<typea, int> b;
}
compiles OK (and is valid code).

Victor
Jul 19 '05 #2

fist off im using pseudocode so if its not "technically" right is not
supposed to be it only supposed to show the meaning. aka e.T

However, i did make a small typeo

A<type,int> _a; should be A<typea,int> _a;
and
A<typea,int> _b; should be A<typeb,int> _b;

and yes its compiles fine in your example because theres only one
instatiation of the template class. it works fine for me also with one
case.

derive another template class using a different type as T.
(hence the meaning of typea and typeb, which are preferabley complex and
not just double or char etc)

Aka
int main()
{
A<typea, int> _a; A<typeb, int> _b;

//and make a member function that attempts to copy
// ie class member funct copy(T &)
// { e _entry;
// read(_entry) <-psuedocode meaning get
// some value for _entry
// (T &)*this) = _entry.T; <- psuedocode}

// Finally, make sure to call the function in main.

_a.copy(.typea.); <-psuedocode
_b.copy(.typeb.);
}

lastly why isnt iimportant.

"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vj************@corp.supernews.com... "dwrayment" <dw*******@rogers.com> wrote...
here is an example of what im trying to do in the most basic form,

template<class T, class I> class A : public T {

typedef struct {I i; T t;} e;
// functions not that important, not the issue
}

struct {... } typea;
struct {... } typeb;


Did you mean to write

struct typea {};
struct typeb {};

???
A<type,int> _a;


What's "type"? Did you mean "typeb"?
A<typea,int> _b;

Problem: when instantiating _b, entry.T is of the form typea


What's "entry"? Did you mean "e"? And there is no e.T. There is
only e.t. Did you mean "e.t" instead of "entry.T"?
and not typeb. so when i try doing something like
entry.T = (T &)(*this) it produces cannot convert
from typea to typeb and vice versa.


Why would you do that?
I have also tried just declaring struct e without typedef and the same

thing
happens. I think the solution involves the keyword
typename but Im having trouble figureing it out.

If anyone can help id appreciate it. Thanks


You'll have to excuse me, I am trying to get all the ducks in a row
here. What are you trying to do, actually?

This (irrelevant things removed):

template<class T, class I> struct A : public T
{
struct
{
I i;
T t;
} entry;

A() { entry.t = *this; }
};

struct typea {};

int main()
{
A<typea, int> b;
}
compiles OK (and is valid code).

Victor

Jul 19 '05 #3
"dwrayment" <dw*******@rogers.com> wrote...

fist off im using pseudocode so if its not "technically" right is not
supposed to be it only supposed to show the meaning. aka e.T [...]


Please read FAQ 5.8. You can find FAQ list here:
http://www.parashift.com/c++-faq-lite/

Victor
Jul 19 '05 #4
i appreciate your trying to help but nothing at that site is useful to what
i want to do. in the meantime i have come up with a "it works" solution
that i am "content with" so i am not rushed to find an answer. but
curiostity kills that cat, so i will work on it evenetuallly. i hate not
being able to do something.
"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:sd*******************@rwcrnsc52.ops.asp.att.n et...
"dwrayment" <dw*******@rogers.com> wrote...

fist off im using pseudocode so if its not "technically" right is not
supposed to be it only supposed to show the meaning. aka e.T [...]


Please read FAQ 5.8. You can find FAQ list here:
http://www.parashift.com/c++-faq-lite/

Victor

Jul 19 '05 #5
lmao. you choose not to use psuedocode because it says so in faq. tff


"Sam Holden" <sh*****@staff.cs.usyd.edu.au> wrote in message
news:slrnbjjkgu.89f.sh*****@staff.cs.usyd.edu.au.. .
On Wed, 13 Aug 2003 05:34:42 GMT, dwrayment <dw*******@rogers.com> wrote:
i appreciate your trying to help but nothing at that site is useful to what i want to do. in the meantime i have come up with a "it works" solution that i am "content with" so i am not rushed to find an answer. but
curiostity kills that cat, so i will work on it evenetuallly. i hate not being able to do something.


Other than the specific FAQ you were directed to that tells you not
to post "pseudocode" to "show the meaning".

And if you had read FAQ 5.4 you (assuming you aren't antisocial) wouldn't
have done the bit below:
"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:sd*******************@rwcrnsc52.ops.asp.att.n et...
"dwrayment" <dw*******@rogers.com> wrote...
>
> fist off im using pseudocode so if its not "technically" right is not
> supposed to be it only supposed to show the meaning. aka e.T [...]

Please read FAQ 5.8. You can find FAQ list here:
http://www.parashift.com/c++-faq-lite/

Victor


Of course you are free to ignore the etiquette common in places
you visit, but it generally means people are less helpful.

--
Sam Holden

Jul 19 '05 #6
On Thu, 14 Aug 2003 04:18:36 GMT, dwrayment <dw*******@rogers.com> wrote:
lmao. you choose not to use psuedocode because it says so in faq. tff


If I wanted to maximise my chances of getting useful help from
others I would, yes.

If I just wanted to get myself killfiled by those who might be able
to help, then no I wouldn't.

[snip full quote]

--
Sam Holden

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Leigh | last post by:
Although I've got over most of my template-related problems, I'm having trouble when I started to use default template parameters. For template type T, I've typedef'd this as object_type and then...
23
by: Eric | last post by:
I've got a fairly simple setup that I thought would work, but I am getting link errors. template <class T> class TType { public: TType( void ) {} virtual ~TType( void ) {}
3
by: darkstorm | last post by:
Hi, Please have a look at this code when compiling it is giving error: error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *' with when I added List<T>:: before...
2
by: Levent | last post by:
Please consider the following Parent and Child template classes: template <class T> class Parent { public: typedef T type; typedef T& ref; /* pack of typedefs */ };
4
by: Matthias Spiller | last post by:
Hi, following problem. I'm writing an Image class and want to use templates: .... template<class TType, int TLayers> class Image { public: Image();
3
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the...
30
by: junky_fellow | last post by:
I was looking at the source code of linux or open BSD. What I found that lots of typedefs were used. For example, consider the offset in a file. It was declared as off_t offset; and off_t is...
7
by: Noah Roberts | last post by:
I have something like the following: template<ENUM X, int I = 0> class Generic { .... }; typedef Generic<Val1> v1_type; typedef Generic<Val2> v2_type;
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
68
by: DaveJ | last post by:
Recently I was working on a project where I came across an issue where the program cored and reported "free(): invalid pointer". I found a resolution for this, but don't fully understand why the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.