Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    May 2005
    Gender
    Male
    Posts
    450

    Default what's C++'s "typename"


    could someone pls give me a simple example of typename? how to use it?

  2. #2
    ScrapeBox Development softtouch's Avatar
    Join Date
    Jan 2004
    Gender
    Male
    Posts
    3,699
    Blog Entries
    1

    Default Re: what's C++'s "typename"

    C++ use the keyword typename if you have a qualified name that refers to a type and depends on a template parameter. Only use the keyword typename in template declarations and definitions.
    The following example illustrates the use of the keyword typename:

    Code:
    template<class T> class A
    {
     T::x(y);
     typedef char C;
     A::C d;
    }
    The statement
    Code:
    T::x(y)
    is ambiguous. It could be a call to function x() with a nonlocal argument y, or it could be a declaration of variable y with
    Code:
    type T::x
    . C++ will interpret this statement as a function call. In order for the compiler to interpret this statement as a declaration, you would add the keyword typename to the beginning of it. The statement
    Code:
    A::C d;
    is ill-formed. The class A also refers to A<T> and thus depends on a template parameter.
    You must add the keyword typename to the beginning of this declaration:

    Code:
    typename A::C d;
    You can also use the keyword typename in place of the keyword class in template parameter declarations.

  3. #3

    Default Re: what's C++'s "typename"

    murag sa akong nabasahan no , kay mo define kag name para reusable imong code..

    ex.

    typedef length= 69 ;

    in your entire code imong gamiton is length na keyword so in case mausab ang value ni length, dili naka mag ukay-ukay sa imng code aron mag usab ni length, anha nalang ka sa imong declaration silbi..

    mao siguro na
    hehe

  4. #4

    Default Re: what's C++'s "typename"

    dili man siguro typedef angay gamiton sa above example kun dili #define. typename could be about the different data type in C++/C like int,float,char?

  5. #5
    ScrapeBox Development softtouch's Avatar
    Join Date
    Jan 2004
    Gender
    Male
    Posts
    3,699
    Blog Entries
    1

    Default Re: what's C++'s "typename"

    I gave the explanation above, this is the correct definition of typename.

  6.    Advertisement

Similar Threads

 
  1. Identify Movies By Their Quotes
    By 8_cRawlin_baby_8 in forum TV's & Movies
    Replies: 3457
    Last Post: 01-30-2020, 08:36 AM
  2. what are your favorite movie quotes / lines of all time?
    By sickn_beautiful in forum TV's & Movies
    Replies: 89
    Last Post: 10-16-2019, 05:28 PM
  3. What's the best tatoo quotes for girls?
    By fenn in forum Trends & Fashion
    Replies: 18
    Last Post: 07-15-2013, 07:28 PM
  4. Whats your favorite Vampire Diaries quote/line?
    By Dadoi in forum TV's & Movies
    Replies: 15
    Last Post: 04-24-2011, 11:53 PM
  5. What is your favourtie Donald Trump quote?
    By mang_erning in forum Business, Finance & Economics Discussions
    Replies: 5
    Last Post: 08-28-2010, 12:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top