Thread: non-dependent name in template function

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    non-dependent name in template function

    Hello everyone,


    I am confused about what Bjarne means below, and I quoted the section name, his words and his sample.

    My question is, what did he mean "A call that by coincidence has an argument that matches an actual template parameter type is not dependent"?

    I think the compile error is because, g (1) function call is not dependent on template parameter, and it should be resolved in the definition phase (not instantiation phase) of template function f. But in definition phase of f, what g is (the symbol g) can not be resolved. So comes the compile error.

    Is my analysis correct? What did Bjarne mean?

    (section C.13.8.1 Dependent Names)

    --------------------
    A call that by coincidence has an argument that matches an actual template parameter type is not dependent. For example,
    --------------------

    Code:
    template <class T> T f (T a)
    {
    	return g (1); // error: no g() in scope and g(1) doesn't depent on T
    }
    
    int g (int);
    
    int z = f (2);

    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Yes, that's correct.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    One of the original questions is not answered. :-)

    What do you think Bjarne means in the following statements along with the sample code? What is "A call that by coincidence"? and "an argument that matches an actual template parameter type is not dependent"? Could you let me know how they reflect in the sample code please?

    --------------------
    A call that by coincidence has an argument that matches an actual template parameter type is not dependent. For example,
    --------------------

    Quote Originally Posted by CornedBee View Post
    Yes, that's correct.

    regards,
    George

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by George2 View Post
    What do you think Bjarne means in the following statements along with the sample code? What is "A call that by coincidence"? and "an argument that matches an actual template parameter type is not dependent"? Could you let me know how they reflect in the sample code please?
    It just means that just because g() takes an int, and T happens to be int, that doesn't magically cause g() to be a dependent name. It's only dependent if T, or another dependent type, occurs in g().

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    occurs in g()
    That would be the call to g(), mind you, not the definition.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks brewbuck,


    I have got your idea.

    Quote Originally Posted by brewbuck View Post
    It just means that just because g() takes an int, and T happens to be int, that doesn't magically cause g() to be a dependent name. It's only dependent if T, or another dependent type, occurs in g().

    Thanks CornedBee,


    Quote Originally Posted by CornedBee View Post
    That would be the call to g(), mind you, not the definition.
    What do you mean above? Could you show some pseudo code please?


    regards,
    George

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Of you understood what brewbuck said, you don't need clarification of what I said.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    Question answered.

    Quote Originally Posted by CornedBee View Post
    Of you understood what brewbuck said, you don't need clarification of what I said.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. function template question
    By Thantos in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2004, 10:40 AM