Re: create an object with variable CLASS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux