C++第十八章:未命名空间--static--extern

声明和定义:这里我们将普通数据变量和函数统称变量。从内存分配角度来说,声明和定义的区别在于声明一个变量不会分配内存,而定义一个变量会分配内存。一个变量可以被声明多次,但是只能被定义一次。
基于以上前提,我们可以把声明和定义类比为指针和内存的关系。我们知道,指针其实就是指向内存的一个符号,变量的定义就好比一块内存区域,而声明就好比它的指针,可以有多个指针指向同一个内存区域,而一个指针只能指向一个内存区域,这样就很好理解为什么变量只能被定义一次,如果被定义多次,那就会分配多个内存,这样你通过变量的声明到底去找哪块内存区域呢,这会是个问题。

int data; //对于数据来说,声明和定义往往是同时存在这样既声明了data同时也定义了data,
extern int data;//只声明未定义

static关键字

static关键字的作用有很多,声明静态全局变量,类的静态成员等。这里主要讨论他在修饰全局变量时与extern的区别。有两点需要注意:

1、static修饰全局变量时,声明和定义是同时给出的
2、static的全局作用域只是自身编译单元

编译单元:
每个cpp就是一个编译单元,每个编译单元相互之间是独立且相互不知的。一个编译单元(Translation Unit)是指一个.cpp文件以及这所include的所有.h文件,.h文件里面的代码将会被扩展到包含它的.cpp文件里,然后编译器编译该.cpp文件为一个.obj文件,后者拥有PE(Portable Executable,即Windows可执行文件)文件格式,并且本身包含的就是二进制代码,但是不一定能执行,因为并不能保证其中一定有main函数。当编译器将一个工程里的所有.cpp文件以分离的方式编译完毕后,再由链接器进行链接成为一个.exe或.dll文件。
还有一点需要说明的是:static也可以修饰局部变量,用static修饰的变量都是保存在静态存储区的,当然全局变量不管用不用static修饰都是存在静态存储区,那全局变量用static修饰和不用static修饰有什么区别呢?区别就在于“全局”的范围是整个工程,还是自身编译单元。

//test1.h
static char g[7] = "123456";//static声明和定义同时给出
void fun1();

//test1.cpp
#include "test1.h"
#include <iostream>
void fun1()
{   
	//g[0] = '9';
	std::cout << g << std::endl;
}

//test2.h
void fun2();


//test2.cpp
#include "test2.h"
#include "test1.h"
#include <iostream>
void fun2()
{
	std::cout << g << std::endl;
}

main.cpp
#include"test1.h"
#include"test2.h"
int main()
{
fun1();
fun2()
return 0;
}

当fun1()中不使用语句g[0] = ‘9’;以上输出结果是

在这里插入图片描述
编译单元test1.cpp中的static char g[7] = “123456”;静态变量在另外一个编译单元test2.cpp中起了作用,似乎只要test2.cpp包含test1.h就好像是可以一起共享的,但实际上是被编译器优化了,如果我们修改fun1()中加上语句g[0] = ‘9’,再看结果:
在这里插入图片描述
发现test2.cpp中的g并没有被修改,所以static修饰的只在同一个编译单元是有效的,再另外一个编译单元通过加上所在头文件只是获得了一份拷贝


extern关键字

当extern不与"C"在一起修饰变量或函数时,如在头文件中: extern int g_Int; 它的作用就是声明函数或全局变量的作用范围的关键字,其声明的函数和变量可以在本模块或者其他模块中使用,记住它是一个声明不是定义!也就是说B模块(编译 单元)要是引用模块(编译单元)A中定义的全局变量或函数时,它只要包含A模块的头文件即可, 在编译阶段,模块B虽然找不到该函数或变量,但它不会报错,它会在连接时从模块A生成的目标代码中找到此函数

//test1.h
static char g[7] = "123456";//extern再头文件先声明
void fun1();

//test1.cpp
char g[7] = "123456";//定义
void fun1()
{   
	g[0] = '9';
	std::cout <<"fun1: "<< g << std::endl;
}
//test2.h
-void fun2();


//test2.cpp
#include "test2.h"
#include "test1.h"
#include <iostream>
void fun2()
{
	std::cout << g << std::endl;
}

main.cpp
#include"test1.h"
#include"test2.h"
int main()
{
fun1();
fun2()
return 0;
}

在这里插入图片描述
从以上结果可以看到,两边都被修改了,因为extern可以跨编译单元使用,只要包含test1.h的头文件即可,所以extern的范围比static的“范围大”

注意:也可以不使用头文件,既在一个编译单元声明,另外一个编译单元定义就可以了
如:记住 可以多次声明,定义只有一次:
但最好不要这样使用,容易搞混乱

/* test.cpp */ 
#include <string> 
#include <stdio.h> 
 
// 声明g_name 
extern std::string g_name;         
 
// 声明和定义void hello() 
void hello()                       
{ 
    printf("hello %s!\n", g_name.c_str()); 
} 
 
/* main.cpp */ 
#include <string> 
 
// 声明和定义g_name 
std::string g_name;    
 
// 声明void hello()            
extern void hello();              
 
int main() 
{ 
    g_name = "Handy" 
    hello(); 
    return 0; 
} 

未命名空间

1.定义在未命名空间的名字可以直接使用,因为没有它的名字来限定,所以会存在二义性问题
2.如果两个文件都存在未命名空间,则两个空间相互无关
3.未命名空间定义的变量拥有静态声明周期:他们在第一次使用前创建,并且直到程序结束才销毁
4.和其他命名空间不同,未命名的命名空间仅在特定文件有效,其作用范围不会跨个多个不同文件,类似static

哈哈,以下错误

自己测试得到结果:c.h中含有未命名空间成员,若a.h b.h都包含c.h,在头文件a.h或者b.h中修改该成员(好像static也存在这个问题),则大家共同被修改,若在a.cpp包含a.h或者b.cpp包含b.h 在他们cpp中修改则只是拷贝副本,互相不影响,类似static也是这样。
所以猜测在头文件一般不会去修改变量

哈哈,以上错误

其实,若光有a.h或者b.h则与main.cpp一起组成了一个编译单元,所以其实是在一个编译单元中变化,当然可以互相改变,
若a.h有a.cpp包含a.h , b.h有b.cpp包含b.h,则他们是两个编译单元了以及main.cpp的编译单元,当然不能跨编译单元,只是拷贝了副本,各自变化,不影响

int i;
namespace {

	int i;
}

int main()
{
	i = 0;//发生二义性,未命名空间也没名字,无法区分
}

如果这样就可以
int i;
namespace A{
	namespace {

		int i;
	}
}

int main()
{
	A::i = 0;//明确
	i = 1;//明确
}
//============================================================================== // WARNING!! This file is overwritten by the Block UI Styler while generating // the automation code. Any modifications to this file will be lost after // generating the code again. // // Filename: D:\NXopen\BaiduSyncdisk\studio\hkjm\ui\hkjm.cpp // // This file was generated by the NX Block UI Styler // Created by: MiCH-CEO // Version: NX 12 // Date: 08-06-2025 (Format: mm-dd-yyyy) // Time: 19:18 (Format: hh-mm) // //============================================================================== //============================================================================== // Purpose: This TEMPLATE file contains C++ source to guide you in the // construction of your Block application dialog. The generation of your // dialog file (.dlx extension) is the first step towards dialog construction // within NX. You must now create a NX Open application that // utilizes this file (.dlx). // // The information in this file provides you with the following: // // 1. Help on how to load and display your Block UI Styler dialog in NX // using APIs provided in NXOpen.BlockStyler namespace // 2. The empty callback methods (stubs) associated with your dialog items // have also been placed in this file. These empty methods have been // created simply to start you along with your coding requirements. // The method name, argument list and possible return values have already // been provided for you. //============================================================================== //------------------------------------------------------------------------------ //These includes are needed for the following template code //------------------------------------------------------------------------------ #include "hkjm.hpp" using namespace NXOpen; using namespace NXOpen::BlockStyler; //------------------------------------------------------------------------------ // Initialize static variables //------------------------------------------------------------------------------ Session *(hkjm::theSession) = NULL; UI *(hkjm::theUI) = NULL; //------------------------------------------------------------------------------ // Constructor for NX Styler class //------------------------------------------------------------------------------ hkjm::hkjm() { try { // Initialize the NX Open C++ API environment hkjm::theSession = NXOpen::Session::GetSession(); hkjm::theUI = UI::GetUI(); theDlxFileName = "hkjm.dlx"; theDialog = hkjm::theUI->CreateDialog(theDlxFileName); // Registration of callback functions theDialog->AddApplyHandler(make_callback(this, &hkjm::apply_cb)); theDialog->AddOkHandler(make_callback(this, &hkjm::ok_cb)); theDialog->AddUpdateHandler(make_callback(this, &hkjm::update_cb)); theDialog->AddInitializeHandler(make_callback(this, &hkjm::initialize_cb)); theDialog->AddDialogShownHandler(make_callback(this, &hkjm::dialogShown_cb)); } catch(exception& ex) { //---- Enter your exception handling code here ----- throw; } } //------------------------------------------------------------------------------ // Destructor for NX Styler class //------------------------------------------------------------------------------ hkjm::~hkjm() { if (theDialog != NULL) { delete theDialog; theDialog = NULL; } } //------------------------------- DIALOG LAUNCHING --------------------------------- // // Before invoking this application one needs to open any part/empty part in NX // because of the behavior of the blocks. // // Make sure the dlx file is in one of the following locations: // 1.) From where NX session is launched // 2.) $UGII_USER_DIR/application // 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly // recommended. This variable is set to a full directory path to a file // containing a list of root directories for all custom applications. // e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat // // You can create the dialog using one of the following way: // // 1. USER EXIT // // 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide" // 2) Invoke the Shared Library through File->Execute->NX Open menu. // //------------------------------------------------------------------------------ extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) { hkjm *thehkjm = NULL; try { UF_initialize(); //开发的许可函数,初始化 thehkjm = new hkjm(); // The following method shows the dialog immediately thehkjm->Show(); } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } if(thehkjm != NULL) { delete thehkjm; thehkjm = NULL; }UF_terminate(); //释放许可函数,结束化 } //------------------------------------------------------------------------------ // This method specifies how a shared image is unloaded from memory // within NX. This method gives you the capability to unload an // internal NX Open application or user exit from NX. Specify any // one of the three constants as a return value to determine the type // of unload to perform: // // // Immediately : unload the library as soon as the automation program has completed // Explicitly : unload the library from the "Unload Shared Image" dialog // AtTermination : unload the library when the NX session terminates // // // NOTE: A program which associates NX Open applications with the menubar // MUST NOT use this option since it will UNLOAD your NX Open application image // from the menubar. //------------------------------------------------------------------------------ extern "C" DllExport int ufusr_ask_unload() { //return (int)Session::LibraryUnloadOptionExplicitly; return (int)Session::LibraryUnloadOptionImmediately; //return (int)Session::LibraryUnloadOptionAtTermination; } //------------------------------------------------------------------------------ // Following method cleanup any housekeeping chores that may be needed. // This method is automatically called by NX. //------------------------------------------------------------------------------ extern "C" DllExport void ufusr_cleanup(void) { try { //---- Enter your callback code here ----- } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } } int hkjm::Show() { try { theDialog->Show(); } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } return 0; } //------------------------------------------------------------------------------ //---------------------Block UI Styler Callback Functions-------------------------- //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //Callback Name: initialize_cb //------------------------------------------------------------------------------ void hkjm::initialize_cb() { try { group0 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group0")); hk2edge = dynamic_cast<NXOpen::BlockStyler::CurveCollector*>(theDialog->TopBlock()->FindBlock("hk2edge")); hk1edge = dynamic_cast<NXOpen::BlockStyler::CurveCollector*>(theDialog->TopBlock()->FindBlock("hk1edge")); hk1sd = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("hk1sd")); hk2sd = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("hk2sd")); group = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group")); hkdj = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("hkdj")); hk2jd = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("hk2jd")); hk1jd = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("hk1jd")); vector0 = dynamic_cast<NXOpen::BlockStyler::SpecifyVector*>(theDialog->TopBlock()->FindBlock("vector0")); bodySelect0 = dynamic_cast<NXOpen::BlockStyler::BodyCollector*>(theDialog->TopBlock()->FindBlock("bodySelect0")); color1 = dynamic_cast<NXOpen::BlockStyler::ObjectColorPicker*>(theDialog->TopBlock()->FindBlock("color1")); color2 = dynamic_cast<NXOpen::BlockStyler::ObjectColorPicker*>(theDialog->TopBlock()->FindBlock("color2")); } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } } //------------------------------------------------------------------------------ //Callback Name: dialogShown_cb //This callback is executed just before the dialog launch. Thus any value set //here will take precedence and dialog will be launched showing that value. //------------------------------------------------------------------------------ void hkjm::dialogShown_cb() { try { //---- Enter your callback code here ----- } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } } //------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ // 应用按钮回调函数 - 读取所有控件数据 int hkjm::apply_cb() { int errorCode = 0; // 错误代码,0表示成功 // 声明变量存储所有控件值 std::vector<NXOpen::Curve*> sectionCurves1; std::vector<NXOpen::Curve*> sectionCurves2; double hk1sdValue = 0.0; double hk2sdValue = 0.0; double hkdjValue = 0.0; double hk1jdValue = 0.0; double hk2jdValue = 0.0; NXOpen::Vector3d directionVector(0.0, 0.0, 1.0); std::vector<NXOpen::Body*> selectedBodies; int colorIndex1 = 0; int colorIndex2 = 0; try { // 获取NX会话和工作部件 NXOpen::Session* theSession = NXOpen::Session::GetSession(); NXOpen::Part* workPart = theSession->Parts()->Work(); NXOpen::UI* theUI = NXOpen::UI::GetUI(); //使用GetUI获取UI对象 // ===== 1. 处理曲线选择器1的值 ===== if (hk1edge) // 检查曲线选择器1控件是否有效 { // 获取曲线选择器1的属性列表 (使用BlockStyler命名空间) NXOpen::BlockStyler::PropertyList* props = hk1edge->GetProperties(); // 获取选中的曲线对象集合 std::vector<NXOpen::TaggedObject*> selObjs = props->GetTaggedObjectVector("SelectedObjects"); // 遍历所有选中的对象 for (NXOpen::TaggedObject* obj : selObjs) { // 将对象转换为曲线型 if (NXOpen::Curve* curve = dynamic_cast<NXOpen::Curve*>(obj)) { sectionCurves1.push_back(curve); } } // 释放属性列表内存 delete props; } // ===== 2. 处理曲线选择器2的值 ===== if (hk2edge) // 检查曲线选择器2控件是否有效 { // 获取曲线选择器2的属性列表 NXOpen::BlockStyler::PropertyList* props = hk2edge->GetProperties(); // 获取选中的曲线对象集合 std::vector<NXOpen::TaggedObject*> selObjs = props->GetTaggedObjectVector("SelectedObjects"); // 遍历所有选中的对象 for (NXOpen::TaggedObject* obj : selObjs) { // 将对象转换为曲线型 if (NXOpen::Curve* curve = dynamic_cast<NXOpen::Curve*>(obj)) { sectionCurves2.push_back(curve); } } // 释放属性列表内存 delete props; } // ===== 3. 获取hk1sd表达式值 ===== if (hk1sd) // 检查表达式控件是否有效 { // 获取表达式控件的属性列表 NXOpen::BlockStyler::PropertyList* props = hk1sd->GetProperties(); // 获取表达式的当前值 hk1sdValue = props->GetDouble("Value"); // 释放属性列表内存 delete props; } // ===== 4. 获取hk2sd表达式值 ===== if (hk2sd) // 检查表达式控件是否有效 { // 获取表达式控件的属性列表 NXOpen::BlockStyler::PropertyList* props = hk2sd->GetProperties(); // 获取表达式的当前值 hk2sdValue = props->GetDouble("Value"); // 释放属性列表内存 delete props; } // ===== 5. 获取hkdj表达式值 ===== if (hkdj) // 检查表达式控件是否有效 { // 获取表达式控件的属性列表 NXOpen::BlockStyler::PropertyList* props = hkdj->GetProperties(); // 获取表达式的当前值 hkdjValue = props->GetDouble("Value"); // 释放属性列表内存 delete props; } // ===== 6. 获取hk1jd表达式值 ===== if (hk1jd) // 检查表达式控件是否有效 { // 获取表达式控件的属性列表 NXOpen::BlockStyler::PropertyList* props = hk1jd->GetProperties(); // 获取表达式的当前值 hk1jdValue = props->GetDouble("Value"); // 释放属性列表内存 delete props; } // ===== 7. 获取hk2jd表达式值 ===== if (hk2jd) // 检查表达式控件是否有效 { // 获取表达式控件的属性列表 NXOpen::BlockStyler::PropertyList* props = hk2jd->GetProperties(); // 获取表达式的当前值 hk2jdValue = props->GetDouble("Value"); // 释放属性列表内存 delete props; } // ===== 8. 获取矢量方向 ===== if (vector0) // 检查矢量控件是否有效 { // 获取矢量控件的属性列表 NXOpen::BlockStyler::PropertyList* props = vector0->GetProperties(); // 获取矢量方向 directionVector = props->GetVector("Vector"); // 释放属性列表内存 delete props; } // ===== 9. 处理选中的实体 ===== if (bodySelect0) // 检查实体选择器控件是否有效 { // 获取实体选择器的属性列表 NXOpen::BlockStyler::PropertyList* props = bodySelect0->GetProperties(); // 获取选中的实体对象集合 std::vector<NXOpen::TaggedObject*> selObjs = props->GetTaggedObjectVector("SelectedObjects"); // 遍历所有选中的对象 for (NXOpen::TaggedObject* obj : selObjs) { // 将对象转换为实体型 if (NXOpen::Body* body = dynamic_cast<NXOpen::Body*>(obj)) { selectedBodies.push_back(body); } } // 释放属性列表内存 delete props; } // ===== 10. 获取颜色选择器1的颜色 ===== if (color1) // 检查颜色选择器控件是否有效 { // 获取颜色选择器的属性列表 NXOpen::BlockStyler::PropertyList* colorProps = color1->GetProperties(); // 获取颜色值(整数向量) std::vector<int> colors = colorProps->GetIntegerVector("Value"); // 获取第一个颜色索引值 if (!colors.empty()) { colorIndex1 = colors[0]; } // 释放属性列表内存 delete colorProps; } // ===== 11. 获取颜色选择器2的颜色 ===== if (color2) // 检查颜色选择器控件是否有效 { // 获取颜色选择器的属性列表 NXOpen::BlockStyler::PropertyList* colorProps = color2->GetProperties(); // 获取颜色值(整数向量) std::vector<int> colors = colorProps->GetIntegerVector("Value"); // 获取第一个颜色索引值 if (!colors.empty()) { colorIndex2 = colors[0]; } // 释放属性列表内存 delete colorProps; } // ===== 执行拉伸操作 ===== if (!sectionCurves1.empty() && hk1sdValue != 0.0) { // 设置撤销标记 NXOpen::Session::UndoMarkId markId = theSession->SetUndoMark( NXOpen::Session::MarkVisibilityVisible, "拉伸操作"); // 创建拉伸构建器 NXOpen::Features::ExtrudeBuilder* extrudeBuilder = workPart->Features()->CreateExtrudeBuilder(nullptr); // 创建截面对象 NXOpen::Section* section = workPart->Sections()->CreateSection( 0.001, 0.001, 0.05); extrudeBuilder->SetSection(section); // 添加曲线到截面 (使用适用于NX 12的方法) for (NXOpen::Curve* curve : sectionCurves1) { // 创建曲线规则 (使用CreateRuleBaseCurve) NXOpen::SelectionIntentRule* curveRule = workPart->ScRuleFactory()->CreateRuleBaseCurve( curve, false); // 不自动链选 // 添加到截面 (使用适用于NX 12的参数) NXOpen::Point3d pointOnCurve = curve->Evaluate(0.5); section->AddToSection( curveRule, // 选择规则 curve, // 曲线对象 nullptr, // 无基准点 nullptr, // 无基准方向 pointOnCurve, // 曲线上的点 NXOpen::Section::ModeCreate, false // 不反转方向 ); } // 设置拉伸方向 (适用于NX 12) NXOpen::Direction* extrudeDirection = workPart->Directions()->CreateDirection( NXOpen::Point3d(0, 0, 0), // 原点 directionVector, // 方向向量 NXOpen::SmartObject::UpdateOptionWithinModeling ); extrudeBuilder->SetDirection(extrudeDirection); // 设置拉伸范围 (适用于NX 12) extrudeBuilder->Limits()->StartExtend()->Value()->SetRightHandSide("0"); extrudeBuilder->Limits()->EndExtend()->Value()->SetRightHandSide( std::to_string(hk1sdValue).c_str()); // 设置布尔操作型(创建新实体) extrudeBuilder->BooleanOperation()->SetType( NXOpen::GeometricUtilities::BooleanOperation::BooleanTypeCreate); // 设置拔模角度 (适用于NX 12) if (hk1jdValue != 0.0) { extrudeBuilder->Draft()->FrontDraftAngle()->SetRightHandSide( std::to_string(hk1jdValue).c_str()); } // 设置偏置参数 (适用于NX 12) if (hk2sdValue != 0.0) { extrudeBuilder->Offset()->StartOffset()->SetRightHandSide("0"); extrudeBuilder->Offset()->EndOffset()->SetRightHandSide( std::to_string(hk2sdValue).c_str()); } // 执行拉伸操作 NXOpen::NXObject* featureNXObject = extrudeBuilder->Commit(); NXOpen::Features::Feature* feature = dynamic_cast<NXOpen::Features::Feature*>(featureNXObject); // 获取特征创建的实体 (适用于NX 12) std::vector<NXOpen::Body*> featureBodies; if (feature) { feature->GetBodies(featureBodies); } if (!featureBodies.empty() && colorIndex1 != 0) { // 设置新创建实体的颜色 UF_OBJ_set_color(featureBodies[0]->Tag(), colorIndex1); } // 清理资源 extrudeBuilder->Destroy(); section->Destroy(); } catch (std::exception& ex) { errorCode = 1; NXOpen::Session* theSession = NXOpen::Session::GetSession(); theSession->NXMessageBox()->Show("错误", NXOpen::NXMessageBox::DialogTypeError, ("操作失败: " + std::string(ex.what())).c_str()); } catch (...) { errorCode = 1; NXOpen::Session* theSession = NXOpen::Session::GetSession(); theSession->NXMessageBox()->Show("错误", NXOpen::NXMessageBox::DialogTypeError, "未知操作错误"); } return errorCode; } //------------------------------------------------------------------------------ //Callback Name: update_cb //------------------------------------------------------------------------------ int hkjm::update_cb(NXOpen::BlockStyler::UIBlock* block) { try { if(block == hk2edge) { //---------Enter your code here----------- } else if(block == hk1edge) { //---------Enter your code here----------- } else if(block == hk1sd) { //---------Enter your code here----------- } else if(block == hk2sd) { //---------Enter your code here----------- } else if(block == hkdj) { //---------Enter your code here----------- } else if(block == hk2jd) { //---------Enter your code here----------- } else if(block == hk1jd) { //---------Enter your code here----------- } else if(block == vector0) { //---------Enter your code here----------- } else if(block == bodySelect0) { //---------Enter your code here----------- } else if(block == color1) { //---------Enter your code here----------- } else if(block == color2) { //---------Enter your code here----------- } } catch(exception& ex) { //---- Enter your exception handling code here ----- hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } return 0; } //------------------------------------------------------------------------------ //Callback Name: ok_cb //------------------------------------------------------------------------------ int hkjm::ok_cb() { int errorCode = 0; try { errorCode = apply_cb(); } catch(exception& ex) { //---- Enter your exception handling code here ----- errorCode = 1; hkjm::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what()); } return errorCode; } //------------------------------------------------------------------------------ //Function Name: GetBlockProperties //Description: Returns the propertylist of the specified BlockID //------------------------------------------------------------------------------ PropertyList* hkjm::GetBlockProperties(const char *blockID) { return theDialog->GetBlockProperties(blockID); }还是有问题,严重性 代码 说明 项目 文件 行 禁止显示状态 错误(活动) E0304 没有与参数列表匹配的 重载函数 "NXOpen::Section::AddToSection" 实例 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 464 错误(活动) E0135 class "NXOpen::ScRuleFactory" 没有成员 "CreateRuleBaseCurve" hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 458 错误(活动) E0415 不存在从 "void" 转换到 "NXOpen::Point3d" 的适当构造函数 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 463 错误(活动) E0140 函数调用中的参数太多 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 463 错误(活动) E0135 class "NXOpen::Features::Feature" 没有成员 "GetBodies" hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 514 错误(活动) E0127 应输入一个语句 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 526 错误(活动) E0530 try 块至少需要一个处理程序 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 553 错误(活动) E0169 应输入声明 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 602 错误(活动) E0169 应输入声明 hkjm D:\NXopen\BaiduSyncdisk\studio\hkjm\hkjm.cpp 608
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值