Posts
[C++][Visual Studio]Visual studio 2010 C++0x new feature: lambda
auto result = lambda(1,2);
auto result = lambda(1,2);
auto lambda = = -> int { return val1 + val2; };
result = lambda();
lambda(1,2);
lambda(1,2);
auto lambda = =, &result { result = val1 + val2; };
lambda();
read morePosts
[C++][Visual Studio]Visual studio 2010 C++0x new feature: nullptr
void Test(int value) { cout << “void Test(int value)”; }
int _tmain(int argc, _TCHAR* argv[]) { Test(NULL); return 0; }
#include “stdafx.h” #include <iostream>
using namespace std;
void Test(int* value) { cout << “void Test(int* value) “; }
void Test(int value) { cout << “void Test(int value) “; }
int _tmain(int argc, _TCHAR* argv[]) { Test(NULL); Test((int*)NULL); Test(nullptr); return 0; }
read morePosts
[C++][Visual Studio]Visual studio 2010 C++0x new feature: auto
#include “stdafx.h” #include <string> #include <list> #include <map>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) { auto x = 1, *y = &x, **z = &y; // Resolves to int. auto a(2.01), *b (&a); // Resolves to double. auto c = ‘a’, *d(&c); // Resolves to char. auto m = 1, &n = m; // Resolves to int.
map<int,list<string>> mapObj; map<int,list<string>>::iterator i1 = mapObj.begin(); auto i2 = mapObj.begin(); auto lambda = []()->int { return 0; }; return 0; }
read morePosts
[C++][Visual Studio]Visual studio 2010 C++0x new feature: static_assert
#include “stdafx.h”
#define DEFAULT_VALUE 0 #define MAX_VALUE 100
const int VALUE = 10;
struct MyStruct { char data[1024]; };
template < class T, int Size > class Vector { static_assert(Size > 0, “Vector size must be bigger than zero!”);
T m_values[Size]; };
int _tmain(int argc, _TCHAR* argv[]) { static_assert( sizeof(void ) == 4, “64-bit code generation is not supported.”); static_assert( MAX_VALUE > DEFAULT_VALUE, “DEFAULT_VALUE must be smaller than MAX_VALUE” ); static_assert( MAX_VALUE > VALUE, “VALUE must be smaller than MAX_VALUE” ); static_assert( sizeof( MyStruct ) < 10241024, “The structure size exceeds stack size” ); Vector<int, 10> intArray; return 0; }
read morePosts
[C++][Visual Studio]Natived C++使用Visual Studio做單元測試
//Act actual = myObj.Add(x, y); //Assert Assert::AreEqual(actual, expected); }; }; }
read more