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 3210954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:38:49+00:00 2026-05-17T14:38:49+00:00

#ifndef __TEST__ #define __TEST__ namespace std { template<typename T> class list; } template<typename T>

  • 0
#ifndef __TEST__
#define __TEST__

namespace std
{
    template<typename T>
    class list;
}

template<typename T>
void Pop(std::list<T> * l)
{
    while(!l->empty())
        l->pop();
}

#endif

and used that function in my main. I get errors. Of course, I know that there are more template params for std::list (allocator I think). But, that is beside the point. Do I have to know the full template declaration of a template class to be able to forward declare it?

EDIT: I wasn’t using a pointer before – it was a reference. I’ll try it out with the pointer.

  • 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-17T14:38:50+00:00Added an answer on May 17, 2026 at 2:38 pm

    The problem is not that you can’t forward-declare a template class. Yes, you do need to know all of the template parameters and their defaults to be able to forward-declare it correctly:

    namespace std {
      template<class T, class Allocator = std::allocator<T>>
      class list;
    }
    

    But to make even such a forward declaration in namespace std is explicitly prohibited by the standard: the only thing you’re allowed to put in std is a template specialisation, commonly std::less on a user-defined type. Someone else can cite the relevant text if necessary.

    Just #include <list> and don’t worry about it.

    Oh, incidentally, any name containing double-underscores is reserved for use by the implementation, so you should use something like TEST_H instead of __TEST__. It’s not going to generate a warning or an error, but if your program has a clash with an implementation-defined identifier, then it’s not guaranteed to compile or run correctly: it’s ill-formed. Also prohibited are names beginning with an underscore followed by a capital letter, among others. In general, don’t start things with underscores unless you know what magic you’re dealing with.

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

Sidebar

Related Questions

I have the following class #ifndef Container_H #define Container_H #include <iostream> using namespace std;
If I create a class like so: // B.h #ifndef _B_H_ #define _B_H_ class
I have this class header //header for class. #ifndef Container_H #define Container_H #include <iostream>
Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace
For example, how can I avoid writing the 'func_name' twice? #ifndef TEST_FUN # define
I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...)
The resource editor keeps wiping out code of this form in my .rc: #ifndef
Okay, I'm trying to implement a templated class of an array-based queue called Queue.
I am getting an error when I declare a class: #include <iostream> #include testing/test.h
I have a section of makefile that has this sort of structure: bob: ifdef

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.