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 * ;
// 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 ...

You should try
*PointerBaseClass = new DerivedClass[ size ];

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 ...

you need to post code so we can see exactly what you are trying to do.

Are you sure DerivedClass is derived from BaseClass?

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 :

private :
BaseClass  ** PointerBaseClass ;
public:
class4 ()
{
PointerBaseClass = new DerivedClass1* [size];
 /* here appear the error C2440: '=' : cannot convert from 'DerivedClass1*' to 'BaseClass  *' */
}

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

bool class4:: enrollStudent (BaseClass & s)
	   {	 DerivedClass1* PointerDerivedClass1 ;
		 PointerDerivedClass1 = dynamic_cast <DerivedClass1*> (& s); // because I use some functions in DerivedClass1 not in BaseClass 
if ( PointerDerivedClass1 )
{
for (int i = 0 ; i < saze; i++)
 {
	if ( PointerBaseClass [i] == NULL)
	{
	    PointerBaseClass [i] =  ; // here the error
	 }
}
}

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


the second error (( Error C2504: 'BaseClass' : base class undefined )), appear in DerivedClass1 and DerivedClass2

class DerivedClass1  :public BaseClass  
{ // here the error
	private :
		.........

   public:.......

Thanks a lot to you for help me...

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;
:(

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 ...

>>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];

BaseClass ** PointerBaseClass ;

this is requesting in this task;
(( in my project ))
and must I solving depended on that

Hiiiiiiiiiii


I founded the error about the two stars,

but still the error about the including >>??!!!!

It's possible to convert a pointer to derived class to a pointer to a base class, but this rule does not bear a relation to Derived** => Base** conversion.
Compare:

Derived* => Base* // derived-to-base pointers conversion, OK
Derived** == (Derived*)* => (Base*)* == Base** // Type1* to Type2*, wrong

Type1 = Derived*
Type2 = Base*
You have two different pointer types Type1 and Type2 and it's impossible to convert a pointer to Type1 to a pointer to Type2.

In other words, you can assign Derived* pointer value to Base* pointer variable because any derived class object is a base object too, but it does not mean that these pointers are the same things. So Base** points to an array (may be a single element) of Base* but not to an array of different Derived* pointers.

Very thanks a lot to you for help me
in the " first error "...

thanks

Nobody can answer to your 1st question without your .h file contents. Obviously, no your base class definition in the other module(s).
Apropos, extern does not bear a relation to class definitions...

Now I try to make the include file one by one in other files.

but still the same number of errors in it.

I put parting the files in header and source files.

In header file:
I including only the header files.
In source files :
I including only the own header file.

My method is correct ..?

Regrettably I don't understand what your method consists in.

Suppose you want to define local derived classes in file1.cpp and file2.cpp. Make base.h file (add it to the project) and place BaseClass definition in this file then include base.h in both file1.cpp and file2.cpp. That's a method.
base.h:

#ifndef BASE_H
#define BASE_H
// if-endif to prevent multiply includes
class Base
{
....
};
// The next class definition for example only:
class Derived: public Base 
{
// Common Base successor
};
#endif

file1.cpp:

#include "base.h"
// Base and Derived are declared here
class Derived1: public Base {
...// visible only in file1.cpp
};
...

file2.cpp:

#include "base.h"
class Derived2: public Derived {
...// visible only in file2.cpp
};
...

Regrettably I don't understand what your method consists in.

I mean as you says ,
but not include one header only;
I need more than one header (.h)and have source files (.cpp).
and all the header files need to gather.

Thank you for your explain.
I Know that you moil with me.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.