| |

VerySource

 Forgot password?
 Register
Search
View: 815|Reply: 5

Always hint when using vector: Can't evaluate the value of expression? ? ?

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 12:30:01
| Show all posts |Read mode
I declare a container type in the header file
typedef std :: vector <int> CityRouterDef;
Then define a class to contain this container
class Population
{
...
CityRouterDef PopIndex;
...
}
Excuse me:
1 Do you need to initialize popIndex in the constructor of the population?
How to write it if needed?
2 I defined the population array later. When population is empty, for example, when popIndex in population [0] is empty, I monitored it and found that the data of popIndex indicates that the value of the expression cannot be calculated. Isn't popIndex initialized? ? But what about popIndex in non-empty population? ? Be puzzled, please give pointers! !!
Reply

Use magic Report

0

Threads

37

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-3 12:33:01
| Show all posts
CityRouterDef is a vector <int> variable. How can it be used as a type?
Reply

Use magic Report

0

Threads

37

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-3 12:39:01
| Show all posts
Ah sorry to read it wrong
Reply

Use magic Report

0

Threads

41

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-3 12:45:01
| Show all posts
Can be initialized
Population :: Population (): PopIndex (32) size initialization
Population :: Population (): PopIndex (iterator1, iterator2) // Iterator
Wait

When there is no data, of course you cannot use population [0].
Reply

Use magic Report

0

Threads

57

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-3 13:45:01
| Show all posts
Generally, only the basic types of data need to be initialized. Generally, wrapped objects have their own initialization process.
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-1-3 17:51:02
| Show all posts
population [0] is an object array element, and popIndex is a member of the object element. According to theory, vector is a system construct that calls the default initialization function, that is, an empty container is constructed, but there should not be a value that cannot be calculated Such a mistake? I know I can't call non-existent data, but is there anything wrong with an empty container?
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