This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: create an object with variable CLASS


You caused i open OOP in C++ book & start reading.My skill is python
programming & C.
But i have a question about previos source:
When i compile my source, i get seg fau, When i run it with gdb, i rcv
following message:
_IO_vfscanf () from /lib/i686/cmov/libc.so.6
Then i changed create_object to following code :
module_management* create_object(char * class_name){
        if (c_find(class_name) == NULL){
                if (strcmp (class_name,"mikrotik") == 0){
                        mikrotik *iu ;
                        return iu;//new mikrotik;
                }//end of strcmp
        }//end of c_find if block
        exit(1);
}//end of func
/////////////////////////////////////

When i compile it, i use following error with GDB:
250		create_object("mikrotik")->printg();
Current language:  auto

/////////////////////////////////////////////////////
I guess it return same Base object, because i tested with following
function:
cout <<typeid(create_object("mikrotik")).name() << endl;
and i see it printed type of Base classs of mikrotik.
 
Do you have any idea?



 
On Wed, 2009-10-28 at 03:11 +0330, Mohsen Pahlevanzadeh wrote:
> Oh, shit, Thank you Andrew & Axel.
> On Tue, 2009-10-27 at 11:34 +0000, Andrew Haley wrote:
> > Mohsen Pahlevanzadeh wrote:
> > > My main file:
> > > int main(){
> > > 	module_management *x;
> > > 	x.printg();
> > > }
> > 
> > Well, that's not going to work, is it?  x is a pointer, not
> > an object.  You need
> > 
> >    x = create_object("mikrotik");
> >    x->printg();
> > 
> > Andrew.
> 
> 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]