Connecting Tech Pros Worldwide Help | Site Map

Templates and Typedefs

  #1  
Old July 19th, 2005, 05:20 PM
dwrayment
Guest
 
Posts: n/a
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






  #2  
Old July 19th, 2005, 05:20 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Templates and Typedefs


"dwrayment" <dwrayment@rogers.com> wrote...[color=blue]
> 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;[/color]

Did you mean to write

struct typea {};
struct typeb {};

???
[color=blue]
> A<type,int> _a;[/color]

What's "type"? Did you mean "typeb"?
[color=blue]
> A<typea,int> _b;
>
>
>
> Problem: when instantiating _b, entry.T is of the form typea[/color]

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"?
[color=blue]
> 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.[/color]

Why would you do that?
[color=blue]
> I have also tried just declaring struct e without typedef and the same[/color]
thing[color=blue]
> happens. I think the solution involves the keyword
> typename but Im having trouble figureing it out.
>
> If anyone can help id appreciate it. Thanks[/color]

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


  #3  
Old July 19th, 2005, 05:20 PM
dwrayment
Guest
 
Posts: n/a

re: Templates and Typedefs



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
[color=blue]
> int main()
> {
> A<typea, int> _a;[/color]
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.);
[color=blue]
> }
>[/color]

lastly why isnt iimportant.



"Victor Bazarov" <v.Abazarov@attAbi.com> wrote in message
news:vjip62btfhgobf@corp.supernews.com...[color=blue]
> "dwrayment" <dwrayment@rogers.com> wrote...[color=green]
> > 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;[/color]
>
> Did you mean to write
>
> struct typea {};
> struct typeb {};
>
> ???
>[color=green]
> > A<type,int> _a;[/color]
>
> What's "type"? Did you mean "typeb"?
>[color=green]
> > A<typea,int> _b;
> >
> >
> >
> > Problem: when instantiating _b, entry.T is of the form typea[/color]
>
> 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"?
>[color=green]
> > 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.[/color]
>
> Why would you do that?
>[color=green]
> > I have also tried just declaring struct e without typedef and the same[/color]
> thing[color=green]
> > happens. I think the solution involves the keyword
> > typename but Im having trouble figureing it out.
> >
> > If anyone can help id appreciate it. Thanks[/color]
>
> 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
>
>[/color]


  #4  
Old July 19th, 2005, 05:20 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Templates and Typedefs


"dwrayment" <dwrayment@rogers.com> wrote...[color=blue]
>
> 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 [...][/color]

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

Victor


  #5  
Old July 19th, 2005, 05:21 PM
dwrayment
Guest
 
Posts: n/a

re: Templates and Typedefs


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.Abazarov@attAbi.com> wrote in message
news:sdi_a.90819$Vt6.29528@rwcrnsc52.ops.asp.att.n et...[color=blue]
> "dwrayment" <dwrayment@rogers.com> wrote...[color=green]
> >
> > 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 [...][/color]
>
> Please read FAQ 5.8. You can find FAQ list here:
> http://www.parashift.com/c++-faq-lite/
>
> Victor
>
>[/color]


  #6  
Old July 19th, 2005, 05:22 PM
dwrayment
Guest
 
Posts: n/a

re: Templates and Typedefs


lmao. you choose not to use psuedocode because it says so in faq. tff






"Sam Holden" <sholden@staff.cs.usyd.edu.au> wrote in message
news:slrnbjjkgu.89f.sholden@staff.cs.usyd.edu.au.. .[color=blue]
> On Wed, 13 Aug 2003 05:34:42 GMT, dwrayment <dwrayment@rogers.com> wrote:[color=green]
> > i appreciate your trying to help but nothing at that site is useful to[/color][/color]
what[color=blue][color=green]
> > i want to do. in the meantime i have come up with a "it works"[/color][/color]
solution[color=blue][color=green]
> > 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[/color][/color]
not[color=blue][color=green]
> > being able to do something.[/color]
>
> 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:
>[color=green]
> > "Victor Bazarov" <v.Abazarov@attAbi.com> wrote in message
> > news:sdi_a.90819$Vt6.29528@rwcrnsc52.ops.asp.att.n et...[color=darkred]
> >> "dwrayment" <dwrayment@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
> >>
> >>[/color][/color]
>
> Of course you are free to ignore the etiquette common in places
> you visit, but it generally means people are less helpful.
>
> --
> Sam Holden
>[/color]


  #7  
Old July 19th, 2005, 05:22 PM
Sam Holden
Guest
 
Posts: n/a

re: Templates and Typedefs


On Thu, 14 Aug 2003 04:18:36 GMT, dwrayment <dwrayment@rogers.com> wrote:[color=blue]
> lmao. you choose not to use psuedocode because it says so in faq. tff[/color]

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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on correct usage of forward declaration of templates Hunk answers 6 January 9th, 2007 02:25 PM
Forward declarations, templates, and typedefs Noah Roberts answers 7 May 3rd, 2006 12:15 AM
template & typedefs declaration problem krema2ren@gmail.com answers 5 December 8th, 2005 01:15 PM
Templates: "implicit typename is deprecated" error and typedef'ing templates Generic Usenet Account answers 3 July 23rd, 2005 07:17 AM
<iosfwd> & typedefs with incomplete types. Steven T. Hatton answers 0 July 23rd, 2005 06:52 AM