[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Use of class1<class2> *pname

Posted on 1998-03-11
6
Medium Priority
?
243 Views
Last Modified: 2010-04-10
I have recently taken on a project where the previous coder has used a lot of statements of the form:

SOME_NAME<double> *ptrname;

I initially thought that SOME_NAME must be a class but I can see no declarations for it in any header files included in (or with) the project.

I would be greatful to anyone who can solve this one which has baffled myself and my colleagues.

Thanks
0
Comment
Question by:gavinpat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 450 total points
ID: 1183345
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183346
SOME_NAME<> is a template class.  If you are not familar with templates, they are a little like C's old macros (#define's) but much safer and more powerful.  (they aren't really that much alike, but the serve the same purposes)

more coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183347
Template classes allow you to create many different classes that contain the same logic but work on different data types.  For example say you want to create a stack class.  you could create a stack that stores integers.  but what if you later need to store characters, or say "class WIDGIT"  You would have to create seperate stack classes for each of these data types.  Template classes automate this.

The template class is sort fo like the recipe for the class in general.  Then you can create specific classes from the template for specific types.

When you see something that is a template class name followed by "<", some type, and ">" that is telling the compiler that you want a template class instantiated (made automatically) for the specfied type.

for example if we declared a stack template class

template<class T> class STACK
{
  int count
 T Ary[100]; // room for 100 items.
}
/// not a good class, but a good example.

Then we could create stacks for characters and integers like this

STACK<char> characterstack;
STACK<int> integer stack;

Note that STACK is not a type, it can't be used like other types (char, int, double)  However, STACK<char> or STACK<anything>  is a type like any other type.  It can be used like any other type  (passed to procedures, used in typedefs, etc.)  It just is a weird looking type.


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:nietod
ID: 1183348
Now if you see SOME_NAME<double> and it compiles, then the template class SOME_NAME is defined somewhere.  it may not be written byt eh programmer who wrote the project, that is, it might not be in the .h files he/she produced.  The standard C++ library contains many templates.  It could be one of those.  (They are defined in include files and those files will be "#include"ed in you source code somewhere.)

If you can't find them.  post some example names here and I'll left you know if they are part of the standard library.
0
 

Author Comment

by:gavinpat
ID: 1183349
Is it legal to have class templates as friend classes such as say:

template <class TEMPLATE_TYPE>
class ALT_MATRIX_ROW

{
      TEMPLATE_TYPE       *pRow;
      
public:
// Other code for class goes in here
//

friend class ALT_MATRIX<TEMPLATE_TYPE>;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183350
Yes, that is legal.  Almost everything that is legal for a non-template is legal for a template.  Derived template classes.  template classes derived from non-template classes.  template classes derived from template classes.  Template classes whose members are template classes.  Template classes that contain private template classes.  Lots of other possibilities are all legel.  Most work.  Implimentation of templates is not 100% yet but they are getting close.  Microsoft VC++ 5.0 supports the standard almost 100% and does a good job with a few quirks.  Borland C++ 5 does less well, but Borland builder is supposidly 100% compliant.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question