Thread: A problem with pointers and objects.

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Question A problem with pointers and objects.

    I am having a bit of trouble here - I know what the problem is, but I am not very well acquainted with the tools of C++.

    To help you scuff through all the nonsense in the below code, go to line 144.
    Code

    I have a class "node", with a subclass "lexicalnode". A third class, "lexicalitem" is a base class. "lexicalnode" and "lexicalitem" each has a pointer which points to another object of the opposite class. The problem is that one of them is declared before the other, meaning I get a compiler error at the last one. How can I solve this?

    If there is any way to separate "lexicalnode" and "lexicalitem" into separate .cpp files without a recursive inclusion, I would be happy for assistance.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Forward declaration.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    Thanks for the answer, but I must ask of you to elaborate on that.
    I may be going a bit fast forward, and I probably should pick "Thinking in C++" out of my bookcase to read it, but I just want to get this over with.
    I presume that forward declaration may be a bit to explain, but I would appreciate any keywords on the topic so I can read up on them.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    If you google for "forward declaration" you'll find a lot of resources that explain how it works. It's a useful technique to speed up compilation times, amongst other things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with pointers to dynamic objects
    By mike_g in forum C++ Programming
    Replies: 20
    Last Post: 04-25-2007, 01:16 PM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  4. Vectors of pointers to objects
    By Myownworstenemy in forum C++ Programming
    Replies: 3
    Last Post: 09-01-2003, 11:23 PM
  5. Objects, or pointers to objects?
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 12-18-2001, 12:57 AM