Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:57:08+00:00 2026-05-27T01:57:08+00:00

I just read the wiki article about CRTP , and I’m a little confused

  • 0

I just read the wiki article about CRTP, and I’m a little confused about template instantiation.

According to the wiki,

member function bodies (definitions) are not instantiated until long
after their declarations.

I don’t quite understand what it means.

Suppose I got a class template:

template <typename T>
class A
{
    public:
        void foo(T t)
        {
            //...
        };
};

When I instantiate the class template A, does it instantiate the member function foo()?

For example:

//in .cpp file
int main()
{
    A<int> a; //question 1
              //class template is instantiated here, isn't it? 
              //What about foo(), is it instantiated too?

    a.foo(10); //question 2
               //according to the quotation, foo() will not be instantiated until it is used.
               //if so, foo() is instantiated right here, not in question 1, right?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:57:09+00:00Added an answer on May 27, 2026 at 1:57 am

    You seem to be confusing one thing:

    Instantiation happens during compilation, not during runtime. Hence you can’t say “on which line” a class template or a function template was instantiated.

    That said, you’re right about the fact that member function templates aren’t instantiated together with class templates.

    You could observe it in such a case: You have the following files

    • template.h (defines class A and function A::foo)
    • a.cpp (uses A)
    • b.cpp (uses A and A::foo)

    Then during compilation of a.cpp, only A would be instantiated. However, during compilation of b.cpp, both would be instantiated.

    Because of this, in case A::foo contained some semantically invalid code for a given set of template parameters, you would get compile errors in b.cpp, but not a.cpp.

    I hope that clears things up!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just read an article on www.songho.ca which indicates that a projection matrix is
I just read this great answer from BalusC about how to upload files with
I just read about the breadth-first search algorithm in the Introduction to Algorithms book
I just read about HTML 5's WebSocket interface. How can I start trying this?
I am new in web development, and read some wiki and discussions about MVC.
I googled a lot and read through the wiki, just could not find out
According to this article http://social.technet.microsoft.com/wiki/contents/articles/handling-transactions-in-sql-azure.aspx SQL Azure default database wide setting is to enable
I just read a blog post about NHibernate's ability to create a GUID from
I just read the Wikipedia article on mock objects , but I'm still not
I just read on this answer (answer has since been removed) and I'm sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.