namespace:
文件的引用,爲函數劃定作用域,限制函數體內變量的作用域。相當於maya中的reference。
例如:
#include <maya/MMatrix.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MVector.h>
namespace testFile
{
MString File;
unsigned int numberSize;
namespace other {
MString File;
unsigned int numberSize;
}
}
void main(){
namespace f = testFile; // 別名: 相當於python中的標籤(對象另一個名稱)
f::other::File = MString("filepath"); // 設置
cout << "the file path is " << f::other::File << endl;
return;
}
using:
表示省略,和namespace搭配使用表示可以省略掉空間域名。
例如:
#pragma once
#include <maya/MMatrix.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MVector.h>
namespace testFile
{
MString File;
unsigned int numberSize;
namespace other {
MString File;
unsigned int numberSize;
}
}
void main(){
using namespace testFile;
other::File = MString("filepath"); // 設置
cout << "the file path is " << other::File << endl;
return;
}