小编Qui*_*ver的帖子

访问类中的结构成员

我有一个.hpp和.cpp文件.我想访问类中的结构中的变量,该类恰好位于.cpp文件中的头.hpp文件中.

在.hpp,我有

class foo{

public:
       struct packet{
         int x;
         u_int y;
      };

};

 foo(const char*name)
:m_name(name){}
Run Code Online (Sandbox Code Playgroud)

在.cpp我做了:

foo *foo_1 = &foo;
printf("The value of x is : %d",foo_1->packet.x);
printf ("The value of y is : %u", foo_1->packet.y);
Run Code Online (Sandbox Code Playgroud)

这样做我收到以下错误:

code_1.cpp:117: error: expected primary-expression before ‘;’ token
code_1.cpp:118: error: invalid use of ‘struct foo::packet’
code_1.cpp:119: error: invalid use of ‘struct foo::packet’
make: *** [code_1] Error 1
Run Code Online (Sandbox Code Playgroud)

我的目标是在cpp文件中获取x和y的值.任何建议/想法将非常感激.

谢谢.

c++ struct pointers structure class

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

打印出矩阵中的值

我有一个任务会随着时间的推移消耗仲裁 CPU 和内存。它为我提供了执行以下 linux 命令的输出:

mpstat -u 1 -P ALL

输出看起来像:

02:22:14 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
02:22:15 PM  all    4.51    0.00    0.11    0.00    0.00    0.00    0.00    0.00   95.37
02:22:15 PM    0    0.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   99.00
02:22:15 PM    1   **78.22**    0.00    0.99    0.00    0.00    0.00    0.00    0.00   20.79

02:22:15 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM    3    0.00    0.00    0.00    0.00    0.00    0.00 …
Run Code Online (Sandbox Code Playgroud)

python regex linux bash

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

标签 统计

bash ×1

c++ ×1

class ×1

linux ×1

pointers ×1

python ×1

regex ×1

struct ×1

structure ×1