| |

VerySource

 Forgot password?
 Register
Search
Author: aleckray

I feel that c ++ is a bad place

[Copy link]

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-1-11 11:09:01
| Show all posts
The reference ra is not pointed to another object here-it just modifies the value of the object (memory block) pointed to by reference ra
Reply

Use magic Report

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-13 12:18:02
| Show all posts
>> If you don't know this, it is often debugged for a long time because of this mechanism.

If you do n’t know, learn more.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-21 22:36:01
| Show all posts
What is a virtual table? I am a novice.
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-22 09:09:01
| Show all posts
TOfinefineboy
It is precisely because of what you said that the behavior the landlord said.

In C ++, value semantics is the basis. This is different from many other object-oriented languages. Pointers are used to express reference semantics (pointers themselves are also values ​​...). The problem the landlord said is actually because of C ++ It is value semantic behavior, and what he wants is to quote something semantic. If you want this kind of thing, you can only implement it yourself. C ++ provides enough support to do this.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Japan

Post time: 2020-1-23 21:00:02
| Show all posts
g791113
 
 
   
At first glance, the landlord has never studied software engineering.

  
 
The first f () is polymorphic.
The second f () is the base class
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-31 05:36:02
| Show all posts
A&ra = * pa;
ra.f ();
ra = c;
ra.f ();

It's wrong upstairs,
Both f are polymorphic and both are pa-> f
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-1-31 12:27:02
| Show all posts
A man is born of a human fuck, a demon is born of a demon fuck, if a demon has humanity, it is not a demon, it is a demon ...
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-31 17:55:16
| Show all posts
Read less, and naturally take longer to debug. Read more
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-2 07:09:01
| Show all posts
class A
{
public:
int v;
A () {}
virtual void f () {cout << "A :: f ()" << endl;}
virtual ~ A () {}
};

class B: public A
{
public:
char * m_str;
B () {m_str = new char [10];}
void f () {cout << "B :: f ()" << endl;}
virtual ~ B () {delete m_str;}
};

The above has added new and delete to class B of the LZ code.
Execute the same main function as LZ. If the = operator will copy the virtual table, it will inevitably cause a memory leak.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-10 13:00:01
| Show all posts
top
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list