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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:32+00:00 2026-05-23T07:21:32+00:00

If I want to use a pointer to a class and I dont do

  • 0

If I want to use a pointer to a class and I dont do any operations on it, we can forward declare the class. But if that happens to be a typedef, why is it not allowed?
In the following example, it compiles only i include the commented code but why does compiler wants to know about it at that point? How do I forward declare something which may be a typedef. Is there any changes in this behavior in c++0x?

#include <iostream>
using namespace std;
/*
template<class T>
class temp;

typedef temp<int> later;
*/
class later;
void somefunc(later*);
int main()
{
  later* l;
  somefunc(l);
  return 0;
}
//The following is in someother file/compilation unit.
template<class T>
struct temp
{
  public:
    void print()
    {
        T t(5);
        std::cout<< "helloworld: " << t << std::endl;
    }
};
typedef temp<int> later;
void somefunc(later* l)
{
  l = new later();
  l->print();
}
  • 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-23T07:21:32+00:00Added an answer on May 23, 2026 at 7:21 am

    A typedef does not create a type it just adds a new name to an existing type, and you cannot forward declare it. I recommend that you read this answer to a different related question, I think it can help in understanding the differences between a typedef and a declaration of a user defined type.

    You can, on the other hand, forward declare the actual type, and then add the typedef in place.

    EDIT: Extending on your particular example:

    After declaring the temp template, the identifier temp is available in the user defined types identifier space (which is different to the rest of the symbols’ identifier space). The typedef will create an alias in the global identifier space by the name of later, so after the commented lines (were they uncommented), the user defined types identifier space will contain temp referring to the template, and the identifier later residing in the global identifier space will refer to the concrete instantiation temp<int>. (What a mouthful of “identifier” and “space”!)

    On the other hand, if you forward declare the class as in the first uncommented line class later;, what you are doing is adding an identifier to the user defined types identifier space. The difference can be seen in the following example:

    class A;           // Creates A identifier only in user defined types space
    typedef int B;     // Creates B identifier in the global identifier space
    
    void A(){}         // Ok: A will refer to void A(); class A will refer to the type
    //void B(){}       // Error: B symbol collides with the typedef
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a transaction log file in CSV format that I want use to
I want to use the MultipleLookupField control in a web page that will run
I want to use the Web Browser control within an mono application, but when
I want to const declare the this pointer received as an argument. static void
I have some code which use 'this' pointer of class which calls this code.
I don't want to use pointers when I don't have to, but here's the
I want to instantiate a base class pointer to point to a newly constructed
I want use groovy findAll with my param to filtering closure filterClosure = {
i want use some data from a website with web service. i have a
Below is my stored procedure. I want use stored procedure select all row of

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.