我想知道是否可以在结构内实现通用引用。代码是:
struct Foo1
ia :: Int
end
struct Foo2{UNKNOWNTYPE}
ref :: UNKNOWNTYPE
ib :: Int
function Foo2{UNKNOWNTYPE}(ref::UNKNOWNTYPE,ib::Int)
o = new{UNKNOWNTYPE}(ref,ib)
return o
end
end
foo1 = Foo1();
foo2 = Foo2{Foo1}(foo1,1)
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,struct Foo2 中变量的类型ref直到运行时才确定。上面的代码不起作用,它显示:“LoadError("main.jl", 6, UndefVarError(:UNKNOWNTYPE))”。
我只是学习函数指针,并想测试它如何与成员函数一起工作.以下代码的编译在标记的位置失败.
# include <iostream>
# include <stdio.h>
using namespace std ;
class TMyClass {
public:
int DoIt ( float a, char b, char c ) {
cout << " TMyClass::DoIt " << endl ;
return a + b + c ;
}
int DoMore ( float a, char b, char c ) {
cout << " TMyClass::DoMore " << endl ;
return a - b + c ;
}
int ( TMyClass::*pt2Member ) ( float, char, char ) ;
int …Run Code Online (Sandbox Code Playgroud) 以下代码中的前两行输出是两个空白行,第三行和第四行是两个不相等的大数字,如:19147336 19147192
class A {
public:
A() : m_i(0) { }
protected:
int m_i;
};
class B {
public:
B() : m_d(0.0) { }
protected:
double m_d;
};
int main() {
A *pa = new A;
B *pb = new B;
std::cout << reinterpret_cast<char*>(pa) << std::endl;
std::cout << reinterpret_cast<char*>(pb) << std::endl;
std::cout << (int)reinterpret_cast<char*>(pa) << std::endl;
std::cout << (int)reinterpret_cast<char*>(pb) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想知道上面代码中reinterpret_cast的返回是什么.谢谢!
以下是我的代码的主要部分(采用"高级linux编程",清单3.7):
void clean_up_child_process ( int signal_number ) {
/* Clean up the child process. */
int status ;
wait ( &status ) ;
printf ( " wait finished \n" ) ;
/* Store its exit status in a global variable. */
child_exit_status = status ;
}
int main() {
/* Handle SIGCHLD by calling clean_up_child_process. */
pid_t child_pid ;
struct sigaction sigchld_action ;
memset ( &sigchld_action, 0, sizeof(sigchld_action) ) ;
sigchld_action.sa_handler = &clean_up_child_process ;
sigaction ( SIGCHLD, &sigchld_action, NULL ) …Run Code Online (Sandbox Code Playgroud)