You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
Markdown
48 lines
1.3 KiB
Markdown
|
3 years ago
|
# Guide to modern C++
|
||
|
|
|
||
|
|
- Essentials of Modern C++ Style [CppCon 2014](https://www.youtube.com/watch?v=xnqTKD8uD64&t=2304s)
|
||
|
|
|
||
|
|
- [Style Guides](https://lefticus.gitbooks.io/cpp-best-practices/content/03-Style.html)
|
||
|
|
|
||
|
|
- [Herb Stutter's style](https://herbsutter.com/elements-of-modern-c-style/)
|
||
|
|
- [Bjarne Stroustrup's C++ Style](https://www.stroustrup.com/bs_faq2.html)
|
||
|
|
|
||
|
|
## C++20
|
||
|
|
- Error :
|
||
|
|
- C2664 - cannot convert ... 'const[4] to char*'
|
||
|
|
- C2132 expression didnot evalute to a constant
|
||
|
|
```C++
|
||
|
|
void myFn(char* data)
|
||
|
|
{
|
||
|
|
std::cout << data;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main()
|
||
|
|
{
|
||
|
|
myFn("ABC"); ==> error
|
||
|
|
myFn(const_cast<char*>("ABC")); ==> OK
|
||
|
|
std::cout << "Hello World!\n";
|
||
|
|
}
|
||
|
|
|
||
|
|
constexpr struct stIniEnumToFilenameMap LogNameMap[] =
|
||
|
|
{
|
||
|
|
{CFileLocation::DEBUG_LOG, const_cast<TCHAR*>("Dbg.log")},
|
||
|
|
{CFileLocation::DEBUG_TIMING_LOG, const_cast<TCHAR*>("DbgTiming.log"},
|
||
|
|
{CFileLocation::GUIEVENT_LOG, const_cast<TCHAR*>("GUIEventLog.log"},
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
- range for loop `for each()`
|
||
|
|
```C++
|
||
|
|
|
||
|
|
for each (auto x in items){} ==> error
|
||
|
|
|
||
|
|
for (auto x : items) {} ==> OK
|
||
|
|
```
|
||
|
|
|
||
|
|
- Error: C2440 'initializing': cannot convert from 'ATL::CA2CA' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
|
||
|
|
```C++
|
||
|
|
std::string strModelName = hardwareIniMotionCard.GetString(osKey.str().c_str(), "Error", FALSE).GetString(); ==> OK - use CString().GetString()
|
||
|
|
```
|