LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 810|回复: 7

here is an error when i use signal() in c++

[复制链接]
发表于 2004-5-29 18:22:07 | 显示全部楼层 |阅读模式
my program is like this:
#include<iostream>
using namespace std;

#include<signal.h>

static void SigWinch(int errno)
{
cout<<"aaa"<<endl;
}

int main()
{
signal(SIGWINCH , SigWinch);
exit(0);
}

when i compile it with g++,there is an error as follow:
[zd@zd test]$ g++ -ggdb3 -o 17 17.cpp
17.cpp: In function `int main()':
17.cpp:13: invalid conversion from `void (*)(int*(*)())' to `void (*)(int)'

but the signal() is void (*signal (int signo , void (*func)(int)))(int)
why it want void (*)(int*(*)())
发表于 2004-5-29 18:59:15 | 显示全部楼层
函数类型不对,去掉static修饰符
发表于 2004-5-29 19:01:32 | 显示全部楼层
最初由 鱼儿小 发表
函数类型不对,去掉static修饰符
依然。。
发表于 2004-5-29 19:36:55 | 显示全部楼层
errno是有定义的,换个别的名字
发表于 2004-5-29 19:57:02 | 显示全部楼层
同意楼上。

errno 是C Runtime的全局错误记录。

static void SigWinch(int errcode) 应该没问题
发表于 2004-5-29 20:37:24 | 显示全部楼层
再不行的话,看看extern "C"
 楼主| 发表于 2004-5-29 21:26:32 | 显示全部楼层
thank you.
the program is solved
 楼主| 发表于 2004-5-29 21:39:30 | 显示全部楼层
but i have still a program.
i write an edit with c++,and want to use signal().
the part of my program is like this:
#include "All.h"
#include "Control.h"
#include "StrView.h"

StrView FirstView;

struct winsize GetWinSize()
{
  struct winsize size;
  if(ioctl(1 , TIOCGWINSZ , (char *)&size) < 0)
    {
      size.ws_col=0;
      size.ws_row=0;
      FirstView.DisplayCommand("TIOCGWINSZ error");
    }
  return size;
}

void SigWinch(int signo)
{
  FirstView.WinSize=GetWinSize();
  FirstView.Display(*(FirstView.str));
}

void SigAlrm(int signo)
{
}

int main (int argc , char *argv[])
{
  try
    {
      if(argc == 1)
        argv=NULL;
      Control control(argv , argc);
      signal(SIGWINCH , SigWinch);
      signal(SIGALRM , SigAlrm);
      move(0 , 0);
      for(;!control.GetNowExit();)
        {
          if(control.GetMode() == COMMANDMODE)
            control.ReadCommand();
          else
            control.EditFile();
        }
    }
  catch(FatalError error)
    {
      cout<<error.GetStr();
    }
}

but when i change the size of window,the function SigWinch() is not executed.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表