小编oli*_*bre的帖子

模板化类嵌套类型typename

我要声明的Itertypename,但没有typedef.
然后,我不能Iter在我的template class声明中使用=>令人沮丧:(请教
我如何使用Iter,或者解释我为什么C++如此讨厌 ......

template <typename T>
struct MyContainer
{
  typedef  std::vector<T>  Vec;
  typename Vec::iterator   Iter;

  void Fo (typename std::vector<T>::iterator);  //ok
  typename std::vector<T>::iterator Ba();       //ok

  void Foo (Iter);   //error: 'Iter' is not a type
  Iter Bar ();       //error: 'Iter' does not name a type
};                   //(gcc 4.1.2)
Run Code Online (Sandbox Code Playgroud)
  1. 为什么typedef不能用来申报Iter?为什么不?
  2. 如何使用Itertemplate class?(例如作为函数参数类型)

编辑
在指令中typename Vec::iterator Iter;,关键字typename表示 …

c++ templates typedef nested-class typename

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

具有常量参数的类声明中的类实例

我无法在另一个类的定义中声明具有常量参数的类的实例.

class Foo
{
    private:
        const int m_a, m_b;
    public:
        Foo(int a, int b) : m_a(a), m_b(b) {}
};

class Bar
{
    public:
        Foo foo1(1,2);
        Foo foo2(2,3);
};
Run Code Online (Sandbox Code Playgroud)

从这里我得到错误:

"error: expected identifier before numeric constant"
"error: expected ',' or '...' before numeric constant"
Run Code Online (Sandbox Code Playgroud)

c++ constructor class member-initialization

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

在Ubuntu 13.04上repo init UnicodeDecodeError

我使用repo-1.19:

$ wget -nv 'http://code.google.com/p/git-repo/downloads/detail?name=repo-1.19'
2013-08-05 02:36:32 URL:http://code.google.com/p/git-repo/downloads/detail?name=repo-1.19 [9673] -> "detail?name=repo-1.19.3" [1]
$ chmod +x repo-1.19 
$ ./repo-1.19 --version
repo version v1.12.2
       (from https://gerrit.googlesource.com/git-repo)
repo launcher version 1.19
       (from /home/u/Téléchargements/repo-1.19)
git version 1.8.1.2
Python 2.7.4 (default, Jul  5 2013, 08:21:57) 
[GCC 4.7.3]
Run Code Online (Sandbox Code Playgroud)

但是当我尝试初始化它时,我有Python UnicodeDecodeError:

$ rm -rf .repo
$ ./repo-1.19 init -u git://github.com/CyanogenMod/android.git -b cm-10.2
Get https://gerrit.googlesource.com/git-repo
remote: Counting objects: 101, done
remote: Finding sources: 100% (101/101)
remote: Total 2533 (delta 1442), reused 2533 (delta 1442)
Receiving objects: …
Run Code Online (Sandbox Code Playgroud)

python git ubuntu android repository

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

为什么在使用选项+执行另一个find命令时会发现抱怨

我已经读过是否可以将find命令传递给另一个find命令的-exec?但我不明白为什么.
我知道这个问题中的示例命令不是很有用,这只是一个示例命令.


尝试运行以下命令:

$ find -type d -exec find {} -ls + -exec echo {} +
find: Only one instance of {} is supported with -exec ... +
Run Code Online (Sandbox Code Playgroud)

从我的角度来看,打印错误是不正确的,因为我的命令由两个组成,-exec每个命令都有自己的最终结果+

find -type d -exec find {} -ls + -exec echo {} +
             <-----------------> <------------->
                 First command    Second command
Run Code Online (Sandbox Code Playgroud)

仅在尝试第一个命令时,我得到了一个不同的错误:

$ find -type d -exec find {} -ls +
find: missing argument to `-exec'
Try 'find --help' for more information.
Run Code Online (Sandbox Code Playgroud)

当然,解决方法是替换+\;.但我想知道为什么我们在上面两个例子中得到这些错误信息??? 请,还提供优雅的解决方案:-) …

shell find command-line-arguments

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

内存分配错误 - 在Linux但不是OSX Unix

我正在为统计包编写一些代码,我首先将数据读入指针数组.我初始化指针并使用malloc分配足够的内存; 但是,我有时会在下面的代码末尾的内存分配中出错.

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "stats.h"

int main(int argc, char **argv) {
FILE *fp, *outFile, *outBin;    // create a file identifier
size_t n, nbins; // # of data points
double *data; // pointer to hold data
double average, variance, *med; // stat returns
int medianComplete, histComplete, i; // return 1 on success
hist_t *Histogram;

// read in the number of bins from exe arguments
nbins = atoi(argv[1]);
nbins = (size_t)nbins;

// open the binary datafile and …
Run Code Online (Sandbox Code Playgroud)

c linux memory fault

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

使用cout打印一个(浮点)小数

我有一个浮点数,我想在十进制后打印一位数.我怎么能用这个cout呢?我尝试了以下代码,但它给出了错误的显示.

#include <iostream>

using namespace std;

int main()
{
    float time = 2.2;
    cout.precision(1);
    cout << time << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ floating-point iostream cout css-position

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

打印两个图案(BEGIN和END)之间的最小线条组,包括这两个图案的线条

输入文件

aaa
Any--END--Pattern
bbb
ANY--BEGIN--PATTERN
ccc                   # do not print
ANY--BEGIN--PATTERN   # print 1
ddd                   # print 2
Any--END--Pattern     # print 3
eee
fff
ANY--BEGIN--PATTERN   # print 4
ggg                   # print 5
Any--END--Pattern     # print 6
hhh                   # print 7
Any--END--Pattern     # print 8
iii                   # do not print
ANY--BEGIN--PATTERN
jjj
Run Code Online (Sandbox Code Playgroud)

想要输出

ANY--BEGIN--PATTERN   # print 1
ddd                   # print 2
Any--END--Pattern     # print 3
ANY--BEGIN--PATTERN   # print 4
ggg                   # print 5
Any--END--Pattern     # print 6
hhh                   # print 7 …
Run Code Online (Sandbox Code Playgroud)

bash shell perl awk sed

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

使用shell脚本的文本文件中的列的总和

我有这样的文件

1814 1
2076 2
2076 1
3958 1
2076 2
2498 3
2858 2
2858 1
1818 2
1814 1
2423 1
3588 12
2026 2
2076 1
1814 1
3576 1
2005 2
1814 1
2107 1
2810 1
Run Code Online (Sandbox Code Playgroud)

我想生成这样的报告

1814 3
2076 6
3958 1
2858 3
Run Code Online (Sandbox Code Playgroud)

基本上计算第1列中每个唯一值的总和

bash shell

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