Error C2440 and C2504

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Error C2440 and C2504

 
0
  #1
Jan 6th, 2009
Hi to all


I have a project, and I found 2 the errors in derived class,
says the first:
'BaseClass' : base class undefined
the number of error is :Error C2504:

and I include the file:
#include "BaseClass.h"
and make declare base class with extern.

but still the error.


.........................
says the second:
'cannot convert from 'DerivedClass **' to 'BaseClass **'.
if I make pointer from base point to derived
// declaration
BaseClass ** PointerBaseClass;
//initialization
PointerBaseClass = new DerivedClass * [size];
// this is code make in another class
the number of error is :error C2440:



Have you got any idea ?
the msdn help is not really clear,
I have made a lot of tries but no issue ....



Thank's for your time ...
Last edited by mini programmer; Jan 6th, 2009 at 12:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: stonerain is an unknown quantity at this point 
Solved Threads: 2
stonerain stonerain is offline Offline
Newbie Poster

Re: Error C2440 and C2504

 
0
  #2
Jan 6th, 2009
You should try
*PointerBaseClass = new DerivedClass[ size ];
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Re: Error C2440 and C2504

 
0
  #3
Jan 6th, 2009
Thank's for your idea.

but If I made that , appear the same error,
but cannot convert from 'DerivedClass *' to 'BaseClass *'
// not from 'DerivedClass **' to 'BaseClass **'.


Thank's for your time ...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Error C2440 and C2504

 
0
  #4
Jan 6th, 2009
you need to post code so we can see exactly what you are trying to do.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: stonerain is an unknown quantity at this point 
Solved Threads: 2
stonerain stonerain is offline Offline
Newbie Poster

Re: Error C2440 and C2504

 
0
  #5
Jan 6th, 2009
Are you sure DerivedClass is derived from BaseClass?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Re: Error C2440 and C2504

 
0
  #6
Jan 6th, 2009
OK..
My project has more than 10 files,
-so I attempt to put which is important.-
My project has many of tasks;
and the all it before now is correct.

I have 4 classes,
2 is derived from BaseClass , and the fourth (class4) contain :
  1. private :
  2. BaseClass ** PointerBaseClass ;
  3. public:
  4. class4 ()
  5. {
  6. PointerBaseClass = new DerivedClass1* [size];
  7. /* here appear the error C2440: '=' : cannot convert from 'DerivedClass1*' to 'BaseClass *' */
  8. }

and if I use the PointerBaseClass as array, appear the same error

  1.  
  2. bool class4:: enrollStudent (BaseClass & s)
  3. { DerivedClass1* PointerDerivedClass1 ;
  4. PointerDerivedClass1 = dynamic_cast <DerivedClass1*> (& s); // because I use some functions in DerivedClass1 not in BaseClass
  5. if ( PointerDerivedClass1 )
  6. {
  7. for (int i = 0 ; i < saze; i++)
  8. {
  9. if ( PointerBaseClass [i] == NULL)
  10. {
  11. PointerBaseClass [i] = ; // here the error
  12. }
  13. }
  14. }

=================================


the second error (( Error C2504: 'BaseClass' : base class undefined )), appear in DerivedClass1 and DerivedClass2
  1. class DerivedClass1 :public BaseClass
  2. { // here the error
  3. private :
  4. .........
  5.  
  6. public:.......



Thanks a lot to you for help me...
Last edited by mini programmer; Jan 6th, 2009 at 2:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Re: Error C2440 and C2504

 
0
  #7
Jan 6th, 2009
Are you sure DerivedClass is derived from BaseClass?

Yes;
I made the last task ( before the day) by heredity, and appear with no any errors;
but now I work in this task ( about polymorsphsim ).

and I not change any thing in derived class , but work in class4;
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Re: Error C2440 and C2504

 
0
  #8
Jan 6th, 2009
Have you got any idea ?
the msdn help is not really clear,
I have made a lot of tries but no issue ....



Thank's for your time ...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Error C2440 and C2504

 
0
  #9
Jan 6th, 2009
>>BaseClass ** PointerBaseClass ;
Why does that have two stars? If you want an array of classes all you need is one star. Two stars indicates either an array of pointers to array of classes, or a pointer to a pointer. The code snippet you posted doesn't seem to need either of those.
BaseClass* PointerBaseClass = new DerivedClass[size];
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 41
Reputation: mini programmer is an unknown quantity at this point 
Solved Threads: 0
mini programmer mini programmer is offline Offline
Light Poster

Re: Error C2440 and C2504

 
0
  #10
Jan 6th, 2009
BaseClass ** PointerBaseClass ;
this is requesting in this task;
(( in my project ))
and must I solving depended on that
Last edited by mini programmer; Jan 6th, 2009 at 5:17 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC