473,396 Members | 1,805 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,396 software developers and data experts.

Wild Cards?

Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have

class shape {
}

class circle: public shape {
};

class triangle: public shape {
};

template <class T>
class red : public T {
}

template <class T>
class blue : public T {
}

template <class T>
class Blueish : public blue<T{
}

now I have a class that manages all blueish objects

class BlueishManager {
public:
void Add(Blueish<shape>* ent) ....
private:
list<Blueish<shape>* __list;
}

The problem is casting a Blueish<triangleto a Blueish<shapecauses
all the functions of the Blueish<triangeto be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)

list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?

Right now I have to have a diffrent list for each object

list<Blueish<triangle>*__listTriangle;
list<Blueish<circle>*__listCircle;

but that might be a pain later if I add a new shape!

Thanks

Matt

Dec 5 '06 #1
4 5184

Ma*************@gmail.com wrote:
Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have

class shape {
}

class circle: public shape {
};

class triangle: public shape {
};

template <class T>
class red : public T {
}

template <class T>
class blue : public T {
}

template <class T>
class Blueish : public blue<T{
}

now I have a class that manages all blueish objects

class BlueishManager {
public:
void Add(Blueish<shape>* ent) ....
private:
list<Blueish<shape>* __list;
}

The problem is casting a Blueish<triangleto a Blueish<shapecauses
all the functions of the Blueish<triangeto be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)

list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?

Right now I have to have a diffrent list for each object

list<Blueish<triangle>*__listTriangle;
list<Blueish<circle>*__listCircle;

but that might be a pain later if I add a new shape!

Thanks

Matt
Your inheritance hierachy is a little strange. I see more in common
between a red_triangle and a blue_triangle than between a red_rectangle
and a red_circle.
Anyway, You could argue that all shapes have_a color, including a
default of Gray or B&W.
Note that is not an is_a relationship. A shape is *not* a color.

class Color { ... };
class Gray : public Color { ... };
class Blue : public Color { ... }; // etc

template < typename C = Gray >
class shape
{
C color; // shapes -have- color
public:
shape() : color() { } // default ctor for target color invoked
virtual ~shape() = 0;
virtual double area() const = 0;
};

template< typename C = Gray >
class triangle : public: shape< C >
{
double height;
double width;
public:
triangle() : height(0.0), width(0.0) { }
...
double area() const { return 0.5 * height * width; }
};

#include <list>

int main()
{
triangle< /*Gray*/ gray_tri;
std::list< shape< /*Gray*/ >* graylist;
graylist.push_back( &gray_tri );

std::list < shape< Blue >* bluelist;
// and so on
}

What you may not want to sacrifice, is those properties that make a
traingle a triangle. Example: how you calculate its area() vs how a
rectangle or circle calculate area().
Color is nothing more than part of the object's composition.

Dec 5 '06 #2

Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now. It's a computer
graphics program that allows you to create diffrent types of tangable
entities, Mobile, Fixed, Active, and asigning them modifiers, a mesh or
camera

class Entity {}

class MobileEntity {}

class FixedEntity {}

template <class T>
class Mobile: public MobileEntity, public T {}

template <class T>
class Fixed:public FixedEntity, public T {}

template <clas T>
class Active: public Mobile<T{}

class Modifier {}

class Mesh : public Modifier {}

class Camera: public Modifier {}
The diffrence between mobile and fixed is the functions they have for
moving around the 3d world.
Active give the function addKey() and then recieves key presses which
can move the mobile object

Now to make an object i say

Mobile<Mesh>* actMesh= new Mobile<Mesh>;

Now Mobile<Meshis a mobile entity, that is a mesh

I don't know if it would make sence to say it is a MobileEntity that
HAS a Mesh because of how the functions are accessed, if I want to
dynamicaly call mesh functions for a list of all types of Mobile,
Fixed, and Active entities i can cast it as a mesh and call thoes,
instead of having to have something inside Mobile Active, and Fixed
classes

((Mesh*)actMesh)->getBoudningSphere();
I will have to think of it a little more I'm sure it is quite possible
to change it to the format you sugested, and if this format still seems
strange to you I will look more into it! But using it so far has
seemed intuitive, the only problem comes when I can have a list of a
Entities with diffrent modifiers I.E. Mobile<MeshMobile<Camera>, I
have to store a diffrent list for each one.

but again, is there any way to do wildcards in c++? Or is it nessisary
to figure out a diffrent structure?

list<Active<? Modifier>*__list

On Dec 5, 2:37 pm, "Salt_Peter" <pj_h...@yahoo.comwrote:
MattWilson.6...@gmail.com wrote:
Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have
class shape {
}
class circle: public shape {
};
class triangle: public shape {
};
template <class T>
class red : public T {
}
template <class T>
class blue : public T {
}
template <class T>
class Blueish : public blue<T{
}
now I have a class that manages all blueish objects
class BlueishManager {
public:
void Add(Blueish<shape>* ent) ....
private:
list<Blueish<shape>* __list;
}
The problem is casting a Blueish<triangleto a Blueish<shapecauses
all the functions of the Blueish<triangeto be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)
list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?
Right now I have to have a diffrent list for each object
list<Blueish<triangle>*__listTriangle;
list<Blueish<circle>*__listCircle;
but that might be a pain later if I add a new shape!
Thanks
MattYour inheritance hierachy is a little strange. I see more in common
between a red_triangle and a blue_triangle than between a red_rectangle
and a red_circle.
Anyway, You could argue that all shapes have_a color, including a
default of Gray or B&W.
Note that is not an is_a relationship. A shape is *not* a color.

class Color { ... };
class Gray : public Color { ... };
class Blue : public Color { ... }; // etc

template < typename C = Gray >
class shape
{
C color; // shapes -have- color
public:
shape() : color() { } // default ctor for target color invoked
virtual ~shape() = 0;
virtual double area() const = 0;

};template< typename C = Gray >
class triangle : public: shape< C >
{
double height;
double width;
public:
triangle() : height(0.0), width(0.0) { }
...
double area() const { return 0.5 * height * width; }

};#include <list>

int main()
{
triangle< /*Gray*/ gray_tri;
std::list< shape< /*Gray*/ >* graylist;
graylist.push_back( &gray_tri );

std::list < shape< Blue >* bluelist;
// and so on

}What you may not want to sacrifice, is those properties that make a
traingle a triangle. Example: how you calculate its area() vs how a
rectangle or circle calculate area().
Color is nothing more than part of the object's composition.
Dec 5 '06 #3
Ma*************@gmail.com wrote:
Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now.
Forget wildcards. Java's generics have almost nothing in common with C++
templates other than notation.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 5 '06 #4
Alright thank you! So the best solution then is to restructure?

Matt

On Dec 5, 3:57 pm, Pete Becker <p...@versatilecoding.comwrote:
MattWilson.6...@gmail.com wrote:
Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now.Forget wildcards. Java's generics have almost nothing in common with C++
templates other than notation.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 5 '06 #5

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

Similar topics

1
by: Steve T | last post by:
I have just contracted with a firm that is using a front-end web interface to access our sales data. They developed it with Microsoft Dotnet, and it uses Microsoft SQL as the database. When I...
2
by: kelvSYC | last post by:
I'm trying to program something along the lines of a "trading card" idea: I have a single copy of the "card" in the program, yet there may be multiple "instances" of the "card", with differing...
2
by: Paweł | last post by:
Hello! I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild" characters like '?' for any one char and...
3
by: topmind | last post by:
I need to search for database text with underlines in it. However, underlines are interpreted as wild-cards in LIKE clause text . I need to know how to escape the underlines so as to be able to...
1
by: panchaga | last post by:
Hi, could any one help me with this select statement. i am using as part of JSP page. i want to use wild cards as part of this select. i am getting error when i use % along with the name. ...
10
by: Arun Nair | last post by:
Can any one help me with this im not getting it even after reading books because there is not much of discussion anywhere a> Implement a calss that represents a playing card. The class should...
1
by: Nitinkcv | last post by:
Hi, I have a textbox and a button. In my textbox i have to enter the query string(say shoes) and on clicking the button takes me to a page show all item related to the search string( in this case...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
7
by: W. eWatson | last post by:
Is it possible to do a search for a wild card string in another string. For example, I'd like to find "v*.dat" in a string called bingo. v must be matched against only the first character in bingo,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.