![]() |
|
#1
|
|||
|
|||
Classes referencing one anotherIs there some way i can create an object refering to a class which will be declared only AFTER the instance of the object??
For example, imagine this situation: CPP / C++ / C Code:
now imagine this: CPP / C++ / C Code:
it works well on c# but not on c++. is there some way to get this to work?? i know i can declare functions first and type the code after it is used, but i can't do that with classes, is there some way?? and, still, this is even more complicated because classes x and y will be in different headers (h. files). is there a way to make this work?? thanks. |
|||
|
#2
|
|||
|
|||
Re: classes referencing one anotherQuote:
The solution is to use a pointer within at least one of the classes. eg. CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: classes referencing one anotherthanks. now i've been able to create the objects, but still it doens't let me use any methods or proprietys or even the constructor of class y inside of class x (he says 'name_of_method' undeclared (first use this function)). is there some way around it??
|
|
#4
|
|||
|
|||
Re: classes referencing one anotherQuote:
|
|
#5
|
|||
|
|||
Re: classes referencing one anotheryes, but everything is declared as public.
forgeting about the cross reference, i'm now trying to make this work. content of x.h: CPP / C++ / C Code:
content of y.h: CPP / C++ / C Code:
content of the .cpp file: CPP / C++ / C Code:
what happens is when i try to compile, dev c++ tells me request for member `ret' in `yyy', which is of non-class type `y*()()' and points this line var = yyy->ret();. which i tried to rewrite many ways like: var = yyy.ret(); var = *yyy->ret(); and etc but none works. and still, i have verified that when i the line y *yyy(); is executed, the y() constructor is not called. what should i do in this case?? thanks. |
|
#6
|
|||
|
|||
Re: classes referencing one anotherQuote:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
http://www.cplusplus.com/doc/tutorial/dynamic.html |
|
#7
|
|||
|
|||
Re: Classes referencing one anotherthanks, that's a good link too, i'm still learning c and am doing it on my own.
but... still, this way: CPP / C++ / C Code:
of course it works well if i include y.h before x.h, but my intention is that one of the classes in y.h will also reference a class from x.h. heheh i'm beginning to assume either it's impossible, or there's something i'm just not being able to figure out. well, let me describe better what really i intend to do for maybe there may be another way around it. what happens is that i'm creating a kinda large library, so instead of using a single .h file, i'm splitting it in differents files. each one of the files correponds to a topic of the library. now, what happens is that many classes of each file will work with classes of other files. now i'll have a lot of trouble if i have to worry about which class is declared first, and still, i'll never get it to work, since many classes will need many other classes the crossings will never get right and still, probably, two classes will work with (reference) each other like the example with x and y classes from my top post. thanks for the help till now, got any ideas?? |
|
#8
|
|||
|
|||
Re: Classes referencing one anotherQuote:
Quote:
Quote:
Last edited by ocicat : 09-Oct-2008 at 02:29.
|
|
#9
|
|||
|
|||
Re: Classes referencing one anotherQuote:
Quote:
but... i was thinking about some stuff i've seen... for example, on .net i have the class frame (which is a box to insert objects inside) and i have the class panel (which is a different box but also used to insert objects inside). and then, i can insert a panel inside of a frame and a frame inside of a panel. so i was thinking about insert an x object inside of an y and an y inside of a x. and i could make this exactly the way i posted above on .net. another example is that a control inside the form (on .net or visual basic 6) has the property called Container... which returns the form he is inside. but well.. i'll rethink this, and when i get to a conclusion, i'll post here, thanks. |
|
#10
|
|||
|
|||
Re: Classes referencing one anotherQuote:
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classes initiation | kdsXchris | C++ Forum | 3 | 05-Jun-2006 04:07 |
| can't figure this out (classes cross referencing) | ehudros | C++ Forum | 4 | 12-May-2006 10:29 |
| Re: Derived FLTK Classes | cable_guy_67 | FLTK Forum | 0 | 26-Jun-2005 21:07 |
| Assistance with classes... | Bravebird | C++ Forum | 7 | 27-Apr-2005 14:17 |
| Fairly simple classes help please | sammacs | C++ Forum | 0 | 30-Nov-2004 10:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The