problems virtually inherited classes 
Author Message
 problems virtually inherited classes

We have 4 c++ classes
class base{
    int opcode;

Quote:
};

class derived1:public virtual base{
    char * filename;
    char * mode;

Quote:
};

class derived2:pubic virtual base{
    unsigned short block;

Quote:
};

class final:public derived1, public derived2{

Quote:
};

we have created a buffer of type unsigned char.
now we want to write the class derived1 to the buffer.
so we use a pointer to the class derived1 and then type cast the base
address of the buffer to the class derived1;
this is how we are doing it

#define mtod (m, t) ((t)(m))
unsigned char buffer[50];

derived1 * drv1_ptr;
drv1_ptr = mtod(buffer, derived1 *);

and now when we try to write to data to the buffer using
drv1_ptr->opcode = somevalue;
drv1_ptr->filename = new char[10];
drv1_ptr->mode = new char[10];

the code compiles but when it tries to write to the global buffer it
gives an segmetation fault......

we have tried the same logic with classes which are not virtually
inherited and works fine .....

kindly help
tushar



Fri, 01 Apr 2005 21:59:13 GMT  
 problems virtually inherited classes

Quote:

> the code compiles but when it tries to write to the global buffer it
> gives an segmetation fault......

How about actually reserving some memory for the object?

Sybren
--
Do you think I'm rude, or don't you understand my answers? Read this page
[http://www.tuxedo.org/~esr/faqs/smart-questions.html#intro] and you'll
understand. You'll also see that I'm not rude in this
(http://www.tuxedo.org/~esr/faqs/smart-questions.html#rtfm) section.



Fri, 01 Apr 2005 22:42:36 GMT  
 problems virtually inherited classes

Quote:

> We have 4 c++ classes

Good for you. Then may I direct you away from here, out the door, turn
left, next door on your left hand, labeled comp.lang.c++? Cheers, and
good luck.

Richard



Fri, 01 Apr 2005 22:42:09 GMT  
 problems virtually inherited classes


Quote:
> We have 4 c++ classes
> class base{
>     int opcode;
> };

Stop right there, take comp.lang.c off your cross-posting list as we do
not discuss C++ in a C langauge newsgroup. Try comp.lang.c++ instead.


Fri, 01 Apr 2005 22:43:19 GMT  
 problems virtually inherited classes

Quote:

> We have 4 c++ classes
> class base{
>     int opcode;
> };

Try comp.lang.c++

<snip>

--

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton



Sat, 02 Apr 2005 00:05:47 GMT  
 problems virtually inherited classes

Quote:

> We have 4 c++ classes

.... take it to comp.lang.c++

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Michael J. Tobler: motorcyclist, surfer,  #    Black holes result
 skydiver, and author: "Inside Linux",     #   when God divides the  
 "C++ HowTo", "C++ Unleashed"              #     universe by zero



Sat, 02 Apr 2005 02:16:07 GMT  
 problems virtually inherited classes

Quote:

> We have 4 c++ classes ...

That's your first problem: you're using C++.

This is neither a Linux nor a C question.

Please find a newsgroup where your question is not off-topic!



Sat, 02 Apr 2005 08:17:18 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. problems creating a object of a inherited class through base class

2. Problem inherting from custom class inherited from MFC class

3. Problem inherting from custom class inherited from MFC class

4. classes that inherit from Windows.Forms.Form - problem with View Designer

5. A problem about multi-inherit class implementation.

6. Problem with inherited classes sizeof

7. Problems inheriting from a common CDialog derived class

8. inherits a class problem?

9. VC++ class inheriting C# class loses base functions

10. Inherit multiple Com Classes into one Com class

11. LNK2001 when compilng a class inheriting from a templatized class

12. class A inheriting from a template of class A

 

 
Powered by phpBB® Forum Software