![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Problem with using classes as Parameters and Return TypesHello all.. I have a project in my Data Structures class in which I have to read in the IMDB data and eventually (Next Project) be able to solve the kevin bacon problem. Anyways I have been setting it up so that there are 5 Classes as follows:
Actor Movie MovieDB ActorDB DB These contain all the information needed to solve the problem. However, I have become hung up on a problem with my code compiling and cant seem to find the error. I will post the Movie and Actor class. Both at some point use each other's class as a Parameter type. I am using MinGW and Eclipse. CPP / C++ / C Code:
CPP / C++ / C Code:
Both Errors Occur at the addMovie/addActor Functions and the errors both look similar and look like this Code:
|
|||
|
#2
|
|||
|
|||
Re: Problem with using classes as Parameters and Return TypesQuote:
Put a forward reference to "Movie" in Actor.h, and put a forward reference to "Actor" in Movie.h: CPP / C++ / C Code:
CPP / C++ / C Code:
That way, no matter which is #included first, the compiler always knows what to do. Note that when the compiler is reading a header compiler doesn't need to know any details of the other class; it just needs to know that is a class. (Like "previews of coming attractions" at the movies.) Regards, Dave |
|
#3
|
|||
|
|||
Re: Problem with using classes as Parameters and Return TypesQuote:
I would only add to this that, if you declare something by value, let's say if you stored an Actor object by value as a member of the Movie object (i.e. you have a member that is declared "Actor theStar;", then the compiler would need the full definition of Actor and not just a forward reference. The reason would be that it needs to allocate storage. When you only use pointers/references ( as you are doing ), then you don't have to allocate storage, and so the compiler doesn't need to know the details of the class. |
|
#4
|
|||
|
|||
Re: Problem with using classes as Parameters and Return TypesI apologize for the late response but the answer given solved my problem thanks.
|
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| a tester class and then some. | postage | Java Forum | 1 | 06-May-2006 15:48 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
| Bounded Buffering? | pablowablo | C Programming Language | 0 | 17-Jan-2005 05:51 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The