?
Solved

template vector?

Posted on 2003-02-23
9
Medium Priority
?
214 Views
Last Modified: 2010-04-01
Hi guys i am trying to template vector that gets 3 differebt data type-int, daouble, char..
The int and double works but i cant assign char data type to the vector..Why is that.. What can i do to make a vetor of char templated..
Thanks in advance..
Carl
0
Comment
Question by:carlNYC
[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
  • 6
  • 3
9 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 8005682
didnt fully understand what you are trying to achieve
0
 

Author Comment

by:carlNYC
ID: 8005690
ok.. what i am trying to do a templete class with member function that takes some int, double and char value. Put whatever the values in a vectors and within the class i have to create another member function that returns the highest int, double and char..My program works with int, and double but it does not work with char..
Something gets wrong when i say
theVector.push_back("Carl");
0
 
LVL 9

Expert Comment

by:tinchos
ID: 8005702
have any code?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:carlNYC
ID: 8005713
template <class T>
T NewClass<T>::MaximumObject2(vector<T> set,T first,T last)
{

     T max;

     if(first==last)
          return set[first];
     else
     {
          max=MaximumObject2(set, first+1, last);
         
          if(set[first]>=max)
               return set[first];
          else
               return max;
     }


}

this is my member function and the problem comes i try to crea some kind of vetor<char> theVector;
theVector.push_back("Mouse");
theVector.push_back("Cat");
etc..
i get an error message..it probably come from the convetion of char >=char whereas i know i can say something like b>a because of ASCII convertaion to binary..
Bue i still get an error..

0
 
LVL 9

Expert Comment

by:tinchos
ID: 8005714
the problem for what i've seen is that you are not using chars

you are using char*

in the case

theVector.push_back( "Carl" );

"Carl" is a char * or a string

try using a string for that case
0
 
LVL 9

Expert Comment

by:tinchos
ID: 8005717
i mean

vector< string >

0
 

Author Comment

by:carlNYC
ID: 8005722
Oh..i really feel stupid..
lol ..thanks...
I will try right away..
0
 
LVL 9

Expert Comment

by:tinchos
ID: 8005732
ok, hope it works
0
 
LVL 9

Accepted Solution

by:
tinchos earned 200 total points
ID: 8005735
in that case, just accept the comment as answer and we're done
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

766 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