我坚持使用模板和范围解析运算符.我在文件中找到了这些行,我无法弄清楚为什么我们在模板函数调用前使用::据我所知,我们只能在引用全局变量时使用::在变量前面.任何想法都会有所帮助
#define CREATE_AND_DECODE_TYPE(Type, buffer, pType) \
::CreateAndDecodeType<Type>(buffer, pType, throwVarBindExceptions, static_cast<Type *>(NULL))
Run Code Online (Sandbox Code Playgroud) 我刚刚编写了一个示例程序来查看删除它的行为
class A
{
~A() {cout << "In destructor \n ";}
public:
int a;
A() {cout << "In constructor \n ";}
void fun()
{
cout << "In fun \n";
delete this;
cout << this->a << "\n"; // output is 0
this->fun_2(); // how m able to call fun_2, if delete this is called first ??
}
void fun_2()
{
cout << "In fun_2 \n";
}
main()
{
A *ptr = new A;
ptr->a = 100;
ptr->fun(); //delete this …Run Code Online (Sandbox Code Playgroud) 我正在编写一段简单的代码。
class A
{
public:
virtual func ()
{ // allocate memory
}
};
class B : public A
{
public:
func ()
{ // some piece of code
// but call base class same function Ist
}
}
main()
{
A *ptr = new B;
ptr->func () //here I want to call base class function first
//and then derived class function
// How to implement ??
}
Run Code Online (Sandbox Code Playgroud)
如何先调用基类函数,然后从派生类调用相同的函数??我不想显式调用每个函数,我只会调用派生类函数,并且应该自动调用基类函数。
我不希望任何构造函数调用这些函数。
有什么办法可以实现这一点,否则这都是垃圾。
我看到很多例子,但我无法理解,如何使用try catch与一个简单的构造函数,我写了一个示例程序:
class A
{
public:
try {
A()
{ cout << "in costr\n"; throw 10;}
}//try closed
catch (int a)
{ cout << "caught 1 \n"; }
};
main()
{
A *ptr = new A;
}
Run Code Online (Sandbox Code Playgroud)
struct confd_data_cbs ssd_shdiag_callback = {
.callpoint = show_diag__callpointid_diag_cp,
.get_object = ssd_common_get_object,
.get_next = ssd_common_get_next,
};
Run Code Online (Sandbox Code Playgroud)
.callback,.get_object,.get_next?
c++ ×4
oop ×2
c ×1
constructor ×1
inheritance ×1
linux ×1
struct ×1
templates ×1
this-pointer ×1
try-catch ×1