hello,tell me the answer please 
Author Message
 hello,tell me the answer please

hello,I miss problem again~~who can tell me the problem and tell me the
answer ,Thanks!
class base
{
public:
 base(){}
 ~base(){}
 virtual void sayhello(){printf("hello ");}
 virtual void sayworld(){printf("world\n");}
 virtual void say(){sayhello();sayworld();}

Quote:
};

class baseone:public base
{
public:
 virtual void sayhello(){}

Quote:
};

class basetwo:public baseone
{
public:
 virtual void sayworld(){printf("kingsoft\n";}//here the debug say error
        //err message ,...................was not matched correctly

Quote:
};

int main()
{
base obj;
baseone obj1;
basetwo obj2;
base* pobj;
pobj->say();
pobj=&obj1;
pobj->say();
pobj=&obj2;
pobj->say();
Quote:
}



Sat, 05 Jun 2004 14:32:00 GMT  
 hello,tell me the answer please
The error is simply that you are missing a matching right parenthesis.

However, you also have a runtime error on the following lines:

Quote:
> base* pobj;
> pobj->say();

You did not initialize pobj the first time, so it is still garbage.  You'll
likely get an access violation.  I think you wanted:
Quote:
> base* pobj = &obj;
> pobj->say();



Sat, 05 Jun 2004 14:57:23 GMT  
 hello,tell me the answer please
The most glaring error is that the first time you use pobj, it is not
initialized.  It doesn't point to anything!  It's just an uninitialized
pointer.

TFM3

Note: Spam-resistant e-mail address


Quote:
> hello,I miss problem again~~who can tell me the problem and tell me the
> answer ,Thanks!
> class base
> {
> public:
>  base(){}
>  ~base(){}
>  virtual void sayhello(){printf("hello ");}
>  virtual void sayworld(){printf("world\n");}
>  virtual void say(){sayhello();sayworld();}
> };

> class baseone:public base
> {
> public:
>  virtual void sayhello(){}
> };

> class basetwo:public baseone
> {
> public:
>  virtual void sayworld(){printf("kingsoft\n";}//here the debug say error
>         file://err message ,...................was not matched correctly
> };

> int main()
> {
> base obj;
> baseone obj1;
> basetwo obj2;
> base* pobj;
> pobj->say();
> pobj=&obj1;
> pobj->say();
> pobj=&obj2;
> pobj->say();

> }



Sat, 05 Jun 2004 15:01:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Tricky Problem: please tell me the answer

2. PLEASE REPLY: Doing a statistics project, PLEASE ANSWER

3. HELLO, PLEASE HELP ME

4. Please tell me how it works?

5. Could somebody please tell me...

6. Could somebody please tell me...

7. Please tell me what went wrong...

8. Could you please tell me something?

9. what is it? please tell me

10. Please tell me the mistake

11. Please look at this code n tell me where i am wrong

12. Tell me about Heap and Stack please.

 

 
Powered by phpBB® Forum Software