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

  • SEARCH
  • Home
  • 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 7248425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:12+00:00 2026-05-28T22:08:12+00:00

I was recently surprised to know that this code compiles (at least on gcc

  • 0

I was recently surprised to know that this code compiles (at least on gcc and MSVC++):

template<typename T>
class A {
public:
    T getT() { return T(); }
};

class B : public A<B> { };

When this doesn’t:

class A;

class B : public A { };

class A {
public:
    B getB() { return B(); }
};

It seems weird to me that a template class could take an incomplete type as a template parameter and have a function that returned one by calling its constructor and still compile. So where exactly are complete types required (or if the list would be shorter, where are they not required)?

  • 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-28T22:08:12+00:00Added an answer on May 28, 2026 at 10:08 pm

    Following are the scenarios where Complete types are not required:

    • Declaring a member to be a pointer or a reference to the incomplete type.
    • Declaring functions which accepts/return incomplete types.
    • Defining functions which accept/return pointers/references to the incomplete type.
    • As a template type argument.

    Basically You are fine using an Incomplete type, at any place where the compiler does not need to know the memory layout of the type.

    As for the template type argument being allowed to be an Incomplete type, the Standard explicitly says so in 14.3.1 Template type arguments

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

Sidebar

Related Questions

I was surprised recently to find that it's possible to have a return statement
I wrote some code recently (ISO/ANSI C), and was surprised at the poor performance
I recently came across this blog post which basically says that we should not
I was recently surprised to note that compiling with /GS (Enable buffer security check)
I've recently started learning Scala and was disappointed (but not surprised) that their generics
I'm always surprised that even after using C# for all this time now, I
I saw a tweet recently that confused me (this was posted by an XNA
I recently finished a class that we're using to tie Access to some WCF
I recently came across some code that looked like: if(sizeof(var,2) == 4) { ...
I have recently become aware that our code has several implementations of a version

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.