Thread: Quick question help~

  1. #1
    Registered User
    Join Date
    Feb 2011

    Exclamation Quick question help~

    "Write a bool function template that accepts a vector of arbitrary type and a value of the same type and returns true if the vector contains the value, and false otherwise".

    I'm reviewing for my final and this is one of the practice questions.

    So this means to create a bool function with a template?

    template <T*>
    bool funk(vector<T*> v)
       for(int i=0;i<v.size();i++)
           if(v[i] == T*)
              return true;
    return false;
    I'm confused when the beginning says "that accepts a vector of arbitrary type and a value of the same type". Could someone please explain this to me, and possibly correct my code?

    Thanks so much for the help!!
    Last edited by bigboybz; 03-22-2011 at 11:50 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It suggests that your template function should accept two parameters.

    I would suggest making both of them reference parameters.

    Your loop is more or less there, if you sort out the parameters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    The template declaration is also wrong. The syntax is basically:
    template<typename NameOfType, typename NameOfType, ...>
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM