Thread: plz help me with this error

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    plz help me with this error

    Hi all!
    can somebody please tell me what is wrong with the following code?
    the header file:
    Code:
    #include <set>
    template <typename T>
    class professional_set
    {
    public:
    	set<typename T> root;
    	set<typename T>:: iterator it;
    }
    in .cpp file I have built an object like this:
    professional_set <int> a;

    when I compile it, it gives this error for the last line:
    missing ';' before identifier 'it'
    missing type specifier - int assumed. Note: C++ does not support default-int

    what do I do now?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Your template class seems to be missing a trailing ;
    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
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Things in standard headers are in the std namespace.
    Members of objects that depend on a template paramater rather than something concrete like int (I mean your iterator declaration), require you to help the compiler by prepending 'typename' to the declaration.
    Unless you have something really convoluted (you don't), typename never goes within the angle brackets in a variable declaration. Just 'T' is enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  2. Replies: 13
    Last Post: 10-08-2010, 05:35 PM
  3. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  4. Replies: 1
    Last Post: 01-11-2007, 05:22 PM
  5. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM