使用 VScode 的原始檔控制,在提交時若出現下圖的訊息
在這找到好辦法 C++ How to detect Windows 10 - Stack Overflow ,保留一份
#include <iostream>
#include <windows.h>
using namespace std;
// 回報 Windows 的版本 (7, 8, 8.1, 10)
double getSysOpType()
{
double ret = 0.0;
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
OSVERSIONINFOEXW osInfo;
*(FARPROC*)&RtlGetVersion =
GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (NULL != RtlGetVersion)
{
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
RtlGetVersion(&osInfo);
ret = (double)osInfo.dwMajorVersion;
}
return ret;
}
int main()
{
cout << getSysOpType() << endl;
return 0;
}
#include <functional> // std::function #include <memory> // std::shared_ptr #include <vector> #include <iostream> using namespace std; // n 取 r 做排列 // 採用逆時旋轉排列法 // 必須 n >= r class Permutation_nPr { // 回報結果 function<void(const shared_ptr<vector<unsigned char> > &, size_t)> m_Report; // 放置要排列的數字 shared_ptr <vector<unsigned char> > m_Digital_Array; // 要做排列的數目值 size_t m_r; void v(size_t n, size_t r) { if (r == 0) m_Report(m_Digital_Array, m_r); else v(n - 1, r - 1); for (size_t j = n; j > 0; --j) { { unsigned char tmp = m_Digital_Array->at(n); m_Digital_Array->at(n) = m_Digital_Array->at(j-1); m_Digital_Array->at(j - 1) = tmp; } if (r == 0) m_Report(m_Digital_Array, m_r); else v(n - 1, r - 1); { unsigned char tmp = m_Digital_Array->at(n); m_Digital_Array->at(n) = m_Digital_Array->at(j-1); m_Digital_Array->at(j - 1) = tmp; } } } public: Permutation_nPr( const function<void(const shared_ptr<vector<unsigned char> > &, size_t)> &Receive ):m_Report(Receive) {} void nPr(size_t n, size_t r) { m_r = r; m_Digital_Array = shared_ptr<vector<unsigned char> >(new vector<unsigned char>(n)); size_t i = n; while (i--) { m_Digital_Array->at(i) = i; } v(n - 1, r - 1); } }; class MsgShow { int N{1}; public: void ResetN(){N = 1;} void operator()( const shared_ptr<vector<unsigned char> > &Digital_Array, size_t r) { cout << N << ":\t"; for (size_t i = Digital_Array->size() - 1; r > 0; --i, --r) cout << (int)Digital_Array->at(i) << ' '; cout << endl; ++N; } }; int main() { MsgShow Report; Permutation_nPr P(Report); cout << '\n' << "4P3 排列:" << endl; Report.ResetN(); P.nPr(4,3); return 0; }
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <vector>
#include <iostream>
using namespace std;
// n 取 r 做排列
// 採用逆時旋轉排列法
// 必須 n >= r
class Permutation_nPr
{
// 回報結果
function<void(const shared_ptr<vector<unsigned char> > &, size_t)> m_Report;
// 放置要排列的數字
shared_ptr <vector<unsigned char> > m_Digital_Array;
// 要做排列的數目值
size_t m_r;
void v(size_t n, size_t r)
{
size_t i = n + 1;
while (i--)
{
if (r == 0)
m_Report(m_Digital_Array, m_r);
else
v(n - 1, r - 1);
unsigned char tmp = m_Digital_Array->at(n);
for (size_t j = n; j > 0; --j)
m_Digital_Array->at(j) = m_Digital_Array->at(j - 1);
m_Digital_Array->at(0) = tmp;
}
}
public: Permutation_nPr( const function<void(const shared_ptr<vector<unsigned char> > &, size_t)> &Receive ) :m_Report(Receive)
{}
void nPr(size_t n, size_t r)
{
m_r = r;
m_Digital_Array =
shared_ptr<vector<unsigned char> >(new vector<unsigned char>(n));
size_t i = n;
while (i--)
{
m_Digital_Array->at(i) = i;
}
v(n - 1, r - 1);
}
};
int N = 1;
void Show(const shared_ptr<vector<unsigned char> > &Digital_Array, size_t r)
{
cout << N << ":\t";
for (size_t i = Digital_Array->size() - 1; r > 0; --i, --r)
cout << (int)Digital_Array->at(i) << ' ';
cout << endl;
++N;
}
int main()
{
Permutation_nPr P(Show);
cout << "4P3 排列:" << endl;
N = 1;
P.nPr(4, 3);
return 0;
}
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <vector>
#include <iostream>
using namespace std;
// n 取 n 做排列
// 採用逆時旋轉排列法
class Permutation_nPn
{
// 回報結果
function<void(const shared_ptr<vector<unsigned char> > &)> m_Report;
// 放置要排的數字
shared_ptr <vector<unsigned char> > m_Digital_Array;
void v(size_t n)
{
if (n == 0)
m_Report(m_Digital_Array);
else
{
size_t i = n + 1;
while (i--)
{
v(n - 1);
unsigned char tmp = m_Digital_Array->at(n);
for (size_t j = n; j > 0; --j)
m_Digital_Array->at(j) = m_Digital_Array->at(j - 1);
m_Digital_Array->at(0) = tmp;
}
}
}
public: Permutation_nPn(
const function<void(const shared_ptr<vector<unsigned char> > &)>
&Receive
)
:m_Report(Receive)
{}
void nPn(size_t n)
{
m_Digital_Array = shared_ptr<vector<unsigned char> >(
new vector<unsigned char>(n));
size_t i = n;
while (i)
{
m_Digital_Array->at(i - 1) = i - 1;
--i;
}
v(n - 1);
}
};
int N = 1;
void Show(const shared_ptr<vector<unsigned char> > &Digital_Array)
{
cout << N << ":\t";
for (size_t i = Digital_Array->size(); i > 0; --i)
cout << (int)Digital_Array->at(i - 1) << ' ';
cout << endl;
++N;
}
int main()
{
Permutation_nPn P(Show);
cout << "4! 排列:" << endl;
N = 1;
P.nPn(4);
return 0;
}
class Base { public: virtual void f() = 0; };
class Derived :public Base { virtual void f() override { } public: };若改為靜態多型可能會像以下這樣:
template<typename DERIVED> class Base { public: void f() { static_cast<DERIVED*>(this)->f_Imp(); } };
class Derived :public Base<Derived> { void f_Imp() { } public:
friend class Base<Derived>; };
m11 m12 m13 m14 x m21 m22 m23 m24 y m31 m32 m33 m34 z m41 m42 m43 m44 1
m11 m12 m13 m14 m21 m22 m23 m24 x y z 1 m31 m32 m33 m34 m41 m42 m43 m44