|
Lines 1187-1190
drawJpg(); // FIXME(joe): Make this code
Websites/webkit.org/code-style.md_sec1
|
| 1187 |
|
1187 |
|
| 1188 |
```cpp |
1188 |
```cpp |
| 1189 |
drawJpg(); // TODO: Make this code handle jpg in addition to the png support. |
1189 |
drawJpg(); // TODO: Make this code handle jpg in addition to the png support. |
| 1190 |
``` |
1190 |
``` |
|
|
1191 |
|
| 1192 |
### Overriding Virtual Methods |
| 1193 |
|
| 1194 |
[](#override-methods) The base level declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must either specify the `override` keyword when overriding the virtual method or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. You never want to annotate a method with more than one of the `virtual`, `override`, or `final` keywords. |
| 1195 |
|
| 1196 |
###### Right: |
| 1197 |
|
| 1198 |
```cpp |
| 1199 |
class Person { |
| 1200 |
public: |
| 1201 |
virtual String description() { ... }; |
| 1202 |
} |
| 1203 |
|
| 1204 |
class Student : public Person { |
| 1205 |
public: |
| 1206 |
String description() override { ... }; // This is correct because it only contains the "override" keyword to indicate that the method is overridden. |
| 1207 |
} |
| 1208 |
|
| 1209 |
``` |
| 1210 |
|
| 1211 |
```cpp |
| 1212 |
class Person { |
| 1213 |
public: |
| 1214 |
virtual String description() { ... }; |
| 1215 |
} |
| 1216 |
|
| 1217 |
class Student : public Person { |
| 1218 |
public: |
| 1219 |
String description() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden and that no subclasses of "Student" can override "description". |
| 1220 |
} |
| 1221 |
|
| 1222 |
``` |
| 1223 |
|
| 1224 |
###### Wrong: |
| 1225 |
|
| 1226 |
```cpp |
| 1227 |
class Person { |
| 1228 |
public: |
| 1229 |
virtual String description() { ... }; |
| 1230 |
} |
| 1231 |
|
| 1232 |
class Student : public Person { |
| 1233 |
public: |
| 1234 |
virtual String description() override { ... }; // This is incorrect because it uses both the "virtual" and "override" keywords to indicate that the method is overridden. Instead, it should only use the "override" keyword. |
| 1235 |
} |
| 1236 |
``` |
| 1237 |
|
| 1238 |
```cpp |
| 1239 |
class Person { |
| 1240 |
public: |
| 1241 |
virtual String description() { ... }; |
| 1242 |
} |
| 1243 |
|
| 1244 |
class Student : public Person { |
| 1245 |
public: |
| 1246 |
virtual String description() final { ... }; // This is incorrect because it uses both the "virtual" and "final" keywords to indicate that the method is overridden and final. Instead, it should only use the "final" keyword. |
| 1247 |
} |
| 1248 |
``` |
| 1249 |
|
| 1250 |
```cpp |
| 1251 |
class Person { |
| 1252 |
public: |
| 1253 |
virtual String description() { ... }; |
| 1254 |
} |
| 1255 |
|
| 1256 |
class Student : public Person { |
| 1257 |
public: |
| 1258 |
virtual String description() { ... }; // This is incorrect because it uses the "virtual" keyword to indicate that the method is overridden. |
| 1259 |
} |
| 1260 |
``` |