473,513 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to include a templatized variable in another class

Howdy,

I got the templatized class Matrix working in the way
it's written in the faq [16.18] , and it works fine as:
Matrix<sqr_T> display(80,25);

However, I'd like to have this variable in the private
section of another class, and I'd like to instantiate in
the class's constructor, with the option of having a size
determined at run-time.

Currently, my class looks like this:

class UI {
public:
UI();
~UI();
//etc
private:
sqr_T display[80][25];
// etc
}

I know I need to add an UI(short, short), but that's
the easy part -- I couldn't figure out the proper
syntax to include the templatized version of display.

Any idea?

TIA

Jul 23 '05 #1
1 1451
Sep

aurgathor wrote:
Howdy,

I got the templatized class Matrix working in the way
it's written in the faq [16.18] , and it works fine as:
Matrix<sqr_T> display(80,25);

However, I'd like to have this variable in the private
section of another class, and I'd like to instantiate in
the class's constructor, with the option of having a size
determined at run-time.

Currently, my class looks like this:

class UI {
public:
UI();
~UI();
//etc
private:
sqr_T display[80][25];
// etc
}

I know I need to add an UI(short, short), but that's
the easy part -- I couldn't figure out the proper
syntax to include the templatized version of display.

Any idea?

TIA


To add a templatized variable into a class is the same as creating an
automatic variable in a function.

private:
Matrix<sqr_T> display;

Now, to initialize it with the values 80 and 25, just use the
constructor initialization list and pass the variables just as if you
were passing them on declaration.

UI() :
display(80, 25)
{
.....

That is, unless you wanted the size to be determined by the
constructor, in which case your presupposition was correct, add a
constructor for UI that takes two doubles (or whatever the types are
for Matrix's constructor) and pass those to it in the initialization
list.

Jul 23 '05 #2

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

Similar topics

3
2946
by: hall | last post by:
I have a problem with my design of a templatized class. I'm trying to figure out how to load and save the data inside it, but can't. My class looks like this ------------------------------------...
10
2508
by: Toke H?iland-J?rgensen | last post by:
Hello. I am quite new to the c++ language, and am still trying to learn it. I recently discovered how using include files would allow me to split up my code into smaller segments, instead of having...
5
7302
by: mrstephengross | last post by:
Ok, I've got code that looks something like this: ================================================== template<typename T1, typename T2> class Base { public: explicit Base(const T1 & t1) {...
5
1683
by: Joseph Turian | last post by:
In a class templatized by class T, I have the following two lines: hash_map<string, T> foo; hash_map<string, T>::const_iterator p; The first line compiles just fine. The second line gives the...
6
1932
by: Ben Taylor | last post by:
I've asked about includes before in this group in order to stop files being #included either twice or not at all, and somebody said to use extern keyword for global variables that need to be used...
3
1077
by: Bob Altman | last post by:
Hi all, This is the first time I've tried to create a templatized function, and I can't get past a linker error. I create a new, unmanaged C++ application and added a class named MyClass. In...
23
3820
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
1
1851
by: tavianator | last post by:
If I had a class with a templatized constructor, like this: class foo { public: template<typename T> foo(); };
4
1725
by: Zachary Turner | last post by:
Is it possible to declare a class with a templatized constructor? I was sure it was, but GCC is giving me errors when I try to do this. Most likely user error. Some example code is: class...
1
7123
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
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5701
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,...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.