小编r3d*_*ice的帖子

为浮动类型重载operator%

我试图重载运算符%因为你不能在双类型上使用模数,

float a = 5.0; 
float b = 5.0;
a  = a % b;
// not allowed
Run Code Online (Sandbox Code Playgroud)

我试图用这种函数重载运算符%:

template <>
MyClass*                MyClass<float>::operator%(Myclass &other)
Run Code Online (Sandbox Code Playgroud)

对于其他涉及浮动的操作,我使用:

template <class T>
MyClass*                MyClass<T>::operator%(MyClass &other)
Run Code Online (Sandbox Code Playgroud)

它从来没有编译实际上我被卡住了,无法找到绕过这个问题的方法,g ++仍然警告我你不能对浮点数执行模数,我的模板语法有问题或者它真的不可能.

c++ templates g++

3
推荐指数
1
解决办法
4451
查看次数

C中的多管道bash风格

我知道有很多线程都在谈论这个问题,但我真的不明白它的实现方式.

我正在尝试创建一个可以执行linux命令的shell,因为ps | grep | less 我已经通过将每个命令及其args放在一个简单的链接列表中来进行解析.

这是我的实现不起作用.希望足够清楚.

if ((son = fork()) < 0)
  return printerr_sys("Unable to fork", 0);
if (son == 0)
  {
    if (first > 1 && data->format[first - 1] &&
    is_directing_elt(data->format[first - 1]) == DIRECT_TPIPE)
       dup2(tube_p[0], STDIN_FILENO);
       first = make_argv(data, first, &argv);
    if (next)
     {
      dup2(tube_v[1], STDOUT_FILENO);
      close(tube_v[0]);
     }
    if (execvp(argv[0], argv) < 0)
      return printerr_cmd(argv[0], 1);
  }
else
  {
    if (next)
        {
           close(tube_v[1]);
           cmdline_executer(data, next, tube_v);
        }
    waitpid(son, &(data->lastcmd), WUNTRACED);
    data->lastcmd = WEXITSTATUS(data->lastcmd); …
Run Code Online (Sandbox Code Playgroud)

c unix shell pipe

1
推荐指数
1
解决办法
2860
查看次数

标签 统计

c ×1

c++ ×1

g++ ×1

pipe ×1

shell ×1

templates ×1

unix ×1