![]() |
|
#1
|
|||
|
|||
A header file do not recognize anotherHi all,
I'm trying to create a method that receive an object as an argument. I get it working when the two classes are defined in the same file.h. However, I would like to know how to do that with two files.h. For instance, this is my code that works, CPP / C++ / C Code:
Now, I would like to write a class in each file (classes1.h, classes2.h) CPP / C++ / C Code:
and CPP / C++ / C Code:
How can I do to classes2.h to recognize the type Cvalues of classes1.h? Thank you. |
|||
|
#2
|
|||
|
|||
Re: A header file do not recognize anotherQuote:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: A header file do not recognize anotherYou also can add a forward declaration if two classes are related to each other.
class a; class b { } if class b using object of class a and vice versa. I hope this help __________________
Linux is the best OS in the world. |
|
#4
|
|||
|
|||
Re: A header file do not recognize anotherI recommand fakepoo suggestion
it is the easiest solution |
|
#5
|
||||
|
||||
Re: A header file do not recognize anotherActually, fakepoo's solution is not only easier it is the standard way you include files that you have created in any program.
Also, don't forget to optimize your code using #ifndef, you don't need to make your x and y values public since you have a function to get those values(which needs to be int so you can return them. So your final code should look like: CPP / C++ / C Code:
CPP / C++ / C Code:
These suggestions should help when you try to debug your code. I hope it makes sense. |
|
#6
|
|||
|
|||
Re: A header file do not recognize anotherBe careful. Most times the #include solution will work, but consider the following:
CPP / C++ / C Code:
CPP / C++ / C Code:
It may not be often that you run into such a situation, but it does happen. And when it does, it is nice to know that you have options. |
Recent GIDBlog
Updates On The All New Toyota VIOS - Part III by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| After execution - Error cannot locate /Skin File? | WSCH | CPP / C++ Forum | 1 | 05-Mar-2005 20:03 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| CD Buring Failed | skanth2000 | Computer Hardware Forum | 1 | 15-Nov-2003 03:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The