RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-604441

user26222930's questions

Martin Hope
user26222930
Asked: 2024-08-12 22:00:16 +0000 UTC

指向类的指针会返回什么?

  • 5

我理解现有的代码。于是我意识到&time这是班级的地址Time。如果注释掉unsigned long time,会出现错误

不存在从“Time”到“unsigned long”的合适转换函数。

因此,我可以猜测该类正在转换为unsigned long.但是,如果类包含多个变量和几个函数,那么到底可以在那里转换什么。也许这个问题很愚蠢,但请像菜鸟一样解释它,或者提供有关该主题的文献的链接,最好有足够的数量。

class Time {

private:
unsigned char sec;
unsigned char min;
unsigned char hour;
unsigned char ...

public:
char data_bufer[7];
char fl_read+end;
char fl_read;
unsigned char long_date;

void init(void);
void read(void);
void...
unsigned char in_BCD_format(unsigned char data);

};

External_bus {

void FRam_Read_long (unsigned long, void*);

};

extern Time time;
extern External_bus ext_buss;

void External_Bus::Flash_Read_long(unsigned char Adr, void* ptr){

unsigned char* Adr_byte;
Adr_byte = (unsigned char*)ptr;
somefunction(Adr, *Adr_byte)

}
 
void main_func{

unsigned char current_oscill;
unsigned long time;
unsigned long event;
line_counter = 0;

if (something){
current_oscill = variable;
while(condition){
ext_buss.Flash_Read_long(current_oscill, &time);  //по сути сюда приходит какое-то значение, но что именно?
}
}

}
c++
  • 1 个回答
  • 66 Views
Martin Hope
user26222930
Asked: 2024-08-01 13:56:18 +0000 UTC

函数参数中的成员函数

  • 5

任务:创建一个类成员函数,其参数既是变量又是另一个类的其他成员函数。

//hpp
class first {
public: 
void function (int func(int, int), int, int, int);
void control (void);
};

//cpp

extern first First;
first First;

int f2(int z){
return z*z;
}

void first::function (int f(int, int), int a, int b, int z){
test_displ.sl_x1 = f(a, b); // вывод на дисплей значения функции 
test_displ.sl_x2 = f2(z);   // вывод на дисплей значения функции f2
}

int f1(int x, int y){
return x+y;
}

void first::control(void){  // 10Hz cycle
inter.function(f1, 1, 2, 3);
}   // работающий код

在这种形式下,一切正常,值显示在屏幕上。我需要该函数f1成为该类的成员函数second。当编写下面的代码时,出现错误A pointer to a bound function may only be used to call the function。据我了解,问题在于函数 f1 不是自由函数,而是成员函数。问题是,我该如何更改它才能使下面的代码起作用?

//hpp
class first {
public: 
void function (int func(int, int), int, int, int);
void control (void);
};

class second {
public:
void f1 (int, int);
}

//cpp

extern first First;
extern second Second;
first First;
second Second;

int f2(int z){
return z*z;
}

void first::function (int f(int, int), int a, int b, int z){
test_displ.sl_x1 = f(a, b); // вывод на дисплей значения функции 
test_displ.sl_x2 = f2(z);   // вывод на дисплей значения функции f2
}

int second::f1(int x, int y){
return x+y;
}

void first::control(void){  // 10Hz cycle
inter.function(Second.f1, 1, 2, 3);
}   // не работающий код
c++
  • 1 个回答
  • 39 Views
Martin Hope
user26222930
Asked: 2024-07-11 14:43:41 +0000 UTC

C++ 中的联合语法

  • 5

我遇到了这段代码,但找不到该条目的含义union以及如何使用它

班级名称:

class Other_Device{

public:
unsigned char Variable;
union SomeBufer {

unsigned char out[2];
struct {

unsigned char StructVariable;

} in;    //end of struct

};   //end of union

SomeBufer A_Buffer ;
SomeBufer T_Buffer ;

void classfunc(void);

};   //end of class

在 cpp 文件本身中,大约有以下对该类的调用:

void Other_device::classfunc(void){
CppVariable = A_Buffer.in.StructVariable;
}

Variable = 0;

extern Other_device other_device;

other_device.A_Buffer.out[0] = 1;
other_device.T_Buffer.out[0] = 1;

我对函数本身不感兴趣;我想了解我是否正确理解了类语法。

相同的代码,但有注释,据我所知

class Other_Device{

public:
unsigned char Variable;
union SomeBufer {

unsigned char out[2]             //создание массива не имеющего отношения к структуре, но относящегося к объединению
struct {                         //создание структуры внутри объединения

unsigned char StructVariable;

} in;    //end of struct         //in нужен для дальнейшего обращения к переменным структуры, а не к массиву out.

};   //end of union

SomeBufer A_Buffer ;             //Вот это не очень понимаю, создание двух массивов содержащих в себе массив out из объединения SomeBufer
SomeBufer T_Buffer ;

void classfunc(void);

};   //end of class

.cpp文件

void Other_device::classfunc(void){
CppVariable = A_Buffer.in.StructVariable;
}

Variable = 0;

extern Other_device other_device;         //то, что необходимо для того, чтобы я мог обращаться к переменным класса Other_device, при этом добавляя в начале other_device. ?

other_device.A_Buffer.out[0] = 1;
other_device.T_Buffer.out[0] = 1;
// и можно ли обращаться к массиву объединения как other_device.SomeBuf.out напрямую, если мне не нужны два массива A_Buffer и T_Buffer с одинаковой структурой и если можно, то как это сделать без ошибки "type name is not allowed"

您能否具体告诉我我的评论:我是否正确理解了编写的代码,如果不正确,出了什么问题?

c++
  • 1 个回答
  • 57 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5