请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430F5335 工具/软件:TI C/C++编译器
当我声明类的全局对象时、例如:
类 RxKey:公共基础{
公共:
RxKey (const char* key_name、const char* str、uint8_t len)
: name(key_name )、s(str)、l(len){}
RxKey (const char* str、uint8_t len)
: name(0), s(str),l(len){}
const char* const name;// regex 字符串
const char* const s; // regex 字符串
const uint8_t l; //最小缓冲器长度
Friend bool operator=(const RxKey& key1, const RxKey* key2);
Friend bool operator=(const RxKey* key1, const RxKey& key2);
Friend bool operator==(const RxKey& key1、const RxKey& key2);
Friend bool 运算符!=(const RxKey& key1、const RxKey& key2);
//---- TO_STRING()--------------------------------------------------
bool TO_string (strings* out){
if (name!= 0){
返回 out->push_str(name);
} 如果(s!= 0){
返回 out->push_str(s);
}
返回 out->push_str("no name");
}
//----列印()----------------------------------------------------------
bool TO_SERIAL_TX (SerialTXInterface* TX){
if (name!= 0){
返回 TX->PRINT (NAME);
} 如果(s!= 0){
返回 TX->PRINT;
}
返回 TX->PRINT ("无名称");
}
bool print_help (SerialTXInterface* TX){
TX->PRINT (s);
if (name!= 0){
TX->PRINT ("、");
TX->PRINT (NAME);
}
返回 true;
}
};
当预主函数运行时、它会调用 malloc 来实例化类、这是否意味着它位于动态存储器空间中? 我认为只有使用新运算符创建的变量才会最终出现在堆上、这种情况不是这样吗?