Click here to Skip to main content
15,850,265 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Assigning pointers from one class to another and Pin
leon de boer15-Oct-16 18:16
leon de boer15-Oct-16 18:16 
GeneralRe: Assigning pointers from one class to another and Pin
Vaclav_19-Oct-16 5:54
Vaclav_19-Oct-16 5:54 
GeneralRe: Assigning pointers from one class to another and Pin
leon de boer19-Oct-16 8:45
leon de boer19-Oct-16 8:45 
NewsHow to provide a Security to a proprietary software or presemtation. Pin
Member 1278313512-Oct-16 21:03
Member 1278313512-Oct-16 21:03 
GeneralRe: How to provide a Security to a proprietary software or presemtation. Pin
jeron113-Oct-16 5:15
jeron113-Oct-16 5:15 
GeneralRe: How to provide a Security to a proprietary software or presemtation. Pin
leon de boer13-Oct-16 9:17
leon de boer13-Oct-16 9:17 
Questionclass is missing "type" - why ? Pin
Vaclav_12-Oct-16 16:00
Vaclav_12-Oct-16 16:00 
AnswerRe: class is missing "type" - why ? PinPopular
leon de boer12-Oct-16 18:45
leon de boer12-Oct-16 18:45 
First you don't put the word "class" in front when using a class, the compiler already knows what IDE_USBD & IDE_HCD are.

However the main problem is you can't forward declare a class and use it as a member
If you don't know these are forward declarations .. you are telling compiler you have a class IDE_USBD & IDE_HCD
class IDE_USBD;
class IDE_HCD;

The problem is it doesn't tell the compiler how big they are and so it can't size them to use as a member. So you need
at least the class data and prototypes to be above where you try and include them into another class
class IDE_USBD {
	// ... this classes data and at least prototypes to functions

public:
	// lets do a prototype
	int Hello(void);
};


class IDE_HCD {
	// ... this classes data and at least prototypes to functions
};

// Class IDE_ILI9341 can now use the above two classes as the compiler can size them
class IDE_ILI9341
{
public:
	IDE_HCD hcd;
	IDE_USBD usbd;
};


// we can put the code for IDE_USBD prototype down here
int IDE_USBD::Hello(void) {

}


Now the second option is close to your original but it has advantages and disadvantages you need to weight up.
That is turn the entries to pointers to the classes. The compiler will be happy because it knows the size of a
pointer.
class IDE_USBD;
class IDE_HCD;

class IDE_ILI9341
{
public:
	IDE_HCD* hcd;
	IDE_USBD* usbd;
};

class IDE_USB {
};

class IDE_HCD {
};


The advantages are you can have the classes in whatever order you want. You can change the
class objects on the fly if you need or not even create instances of them if not required.
So you get a fair amount of flexibility.

The downside is you have to call the class functions by pointer hcd->function(blah blah)
from within your class. That makes the code ever so fractionally slower than the other.
We aren't talking very much and the flexibility sometimes makes it very attractive.

The big thing in this form is that class IDE_USB and IDE_USBD will not auto create (its
only a pointer after all). You need to make sure you manually create an instance of the
classes to the pointer in your constructor of IDE_ILI9341. So your constructor must contain
the two lines to actually create the classes to the pointers
 hcd = new IDE_HCD ( /* .. parameters it takes ..*/ );
usbd = new IDE_USB ( /* .. parameters it takes ..*/ );


You should also dispose of them in IDE_ILI9341 destructor. As the construction used new it
becomes your responsibility to destroy them as they have no scope to auto dispose.
In vino veritas


modified 13-Oct-16 0:29am.

AnswerRe: class is missing "type" - why ? Pin
Graham Breach13-Oct-16 0:11
Graham Breach13-Oct-16 0:11 
QuestionObject Creation of an class? Pin
Mathan_CodeProject11-Oct-16 6:17
Mathan_CodeProject11-Oct-16 6:17 
AnsweralternatRe: Object Creation of an class? Pin
leon de boer11-Oct-16 6:50
leon de boer11-Oct-16 6:50 
GeneralRe: alternatRe: Object Creation of an class? Pin
Mathan_CodeProject12-Oct-16 0:02
Mathan_CodeProject12-Oct-16 0:02 
AnswerRe: Object Creation of an class? Pin
Krishnakumartg11-Oct-16 20:46
Krishnakumartg11-Oct-16 20:46 
GeneralRe: Object Creation of an class? Pin
Mathan_CodeProject12-Oct-16 0:01
Mathan_CodeProject12-Oct-16 0:01 
AnswerRe: Object Creation of an class? Pin
Midi_Mick11-Oct-16 23:13
professionalMidi_Mick11-Oct-16 23:13 
GeneralRe: Object Creation of an class? Pin
Mathan_CodeProject12-Oct-16 0:01
Mathan_CodeProject12-Oct-16 0:01 
QuestionC++ syntax Pin
Ratul Thakur10-Oct-16 22:35
Ratul Thakur10-Oct-16 22:35 
AnswerRe: C++ syntax Pin
CPallini10-Oct-16 22:49
mveCPallini10-Oct-16 22:49 
AnswerRe: C++ syntax Pin
Richard MacCutchan10-Oct-16 22:50
mveRichard MacCutchan10-Oct-16 22:50 
AnswerRe: C++ syntax Pin
David Crow11-Oct-16 7:20
David Crow11-Oct-16 7:20 
QuestionOne more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_9-Oct-16 7:18
Vaclav_9-Oct-16 7:18 
AnswerRe: One more error using function pointers - void value not ignored as it ought to be Pin
Richard MacCutchan9-Oct-16 7:36
mveRichard MacCutchan9-Oct-16 7:36 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_9-Oct-16 8:53
Vaclav_9-Oct-16 8:53 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer10-Oct-16 0:11
leon de boer10-Oct-16 0:11 
AnswerRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer9-Oct-16 22:42
leon de boer9-Oct-16 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.