Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

template vector?

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
carlNYC
Asked:
carlNYC
  • 6
  • 3
1 Solution
 
tinchosCommented:
didnt fully understand what you are trying to achieve
0
 
carlNYCAuthor Commented:
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
 
tinchosCommented:
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!

 
carlNYCAuthor Commented:
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
 
tinchosCommented:
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
 
tinchosCommented:
i mean

vector< string >

0
 
carlNYCAuthor Commented:
Oh..i really feel stupid..
lol ..thanks...
I will try right away..
0
 
tinchosCommented:
ok, hope it works
0
 
tinchosCommented:
in that case, just accept the comment as answer and we're done
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now