Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neonfaktory

2 Layer Template Structures Useless?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have my GUI design figured out. I use my standard Linked List class that I''ve been using for the rest of my program to hold my master list of GUI elements. It is obviously templated. However, my GUI class is also templated. Like I''m sure others have done, all the buttons and textboxes are "windows" but with different aspects to them. 1 scroll bar on the screen might be altering an "int" while another might be altering a "float". The natural solution is to make the GUI class templated. But there''s the problem. Upon declaration of the master gui list "GUILIST" that keeps track of all the elements, it requires you to define what type of template the actual GUI elements in that list will be... defeating the purpose of having them templated if they all have to be the same type anyway. Soo, am I doing this wrong? Can I have a templated Linked List class that holds differently templated GUI elements? Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
don''t make the GUI class templated. Just derrive from a base class and store pointers.

Share this post


Link to post
Share on other sites
... That''s pretty general. "store pointers"? Pointers to what? The values the GUI elements are changing? If so, that is why the class is templated because those values could be the "int"s I store ammo with or the "float"s I use to store weapon-specific percentages with.

Besides, thats not the main point of the post. Can you have a templated class use another templated class as a template without "fixing" the enclosed template to a specific datatype? Thanks again for any help

Share this post


Link to post
Share on other sites
Yep, a GUI system is actually a perfect candidate for a polymorphic inheritance tree. Ie. you have a CDialog base class, with standard control and event management functionality (mostly implemented by virtual functions). From that base class, you derive your individual controls:

class CDialog { /* base class functionality */ }

class CButton : public CDialog { /* ... */ }

class CDropdown : public CListbox, CButton { /* ... */ }

class CSpecialDropdown : public CDropdown { /* ... */ }

etc...

About your approach: well, I don't knwo your details, but it sounds like you're abusing the template feature. If you wanted a float/int Scrollbar, then simply template the derived type:

template <class T> CScrollbar : public CWhatever { /* ... */ }


[edited by - Yann L on May 7, 2003 6:03:20 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by neonfaktory
Besides, thats not the main point of the post. Can you have a templated class use another templated class as a template without "fixing" the enclosed template to a specific datatype? Thanks again for any help


Short answer? No.

Share this post


Link to post
Share on other sites
To Yann:
What you mentioned is exactly what I'm doing, "template CScrollbar : public CWhatever" more or less. The problem arises when I want to create a Linked List of them. The Linked List class itself is templated, and when I try to make a list of the templated "CScrollbar" class with the already templated "LinkList" class, it asks to know what template the "CScrollbar" class will be upon declaration, instead of leaving it open to determine later, defeating the whole point of making the CScrollbar class templated...

Is there any way to work around this?

[edited by - neonfaktory on May 7, 2003 12:04:21 AM]

Share this post


Link to post
Share on other sites
quote:
Can you have a templated class use another templated class as a template without "fixing" the enclosed template to a specific datatype?
Yes, of course.
  template<typename T>
class SomeClass {
};

template<template<typename> class K>
class SomeOtherClass {
public:
typedef K<int> whatever;
};

int main()
{
typedef SomeOtherClass<SomeClass>::whatever whatever;
}
This should be mentioned in any good C++ book.

- lmov

Share this post


Link to post
Share on other sites
Well, maybe this will clear it up some, because I didn't think what I was doing was that complicated...

          
template<class itemType>
class CList // My Linked List Class - Works Fine

...
template<class itemType>
class GUI // My Gernerac GUI Class

...

// Then I simply want to be able to say:

CList<GUI> GUILIST; // <--- Doesn't work, says "GUI" needs a class type


// So I can do:

GUILIST.Add(new GUI(...)); // And pass ints/floats/etc. to the GUI constructor


// ^^^ All this does not work.

// The line that declares "GUILIST" gives an error about "GUI" needing a class type, as in...


CList<GUI<type>> GUILIST; // <--- Doesn't work either (bad syntax)



Whatever the syntax is, it defeats the purpose of me being able to add GUIs with different templated types to the GUILIST... Gah!

*EDIT* Code Examples needed source tags

[edited by - neonfaktory on May 8, 2003 11:00:42 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!