第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如果需要函數(shù)指針數(shù)組接收參數(shù),這個(gè)該怎么操作呢?

如果需要函數(shù)指針數(shù)組接收參數(shù),這個(gè)該怎么操作呢?

MM們 2021-07-26 20:18:17
class Base{private:int x;int y;public:Base();Base(int x,int y);virtual void draw();void move();};class Poit :virtual public Base{public:Poit();Poit(int x,int y);void draw();};class Line :virtual public Base{private:int a;int b;public:Line();Line(int a,int b,int x,int y);void draw();};class Circle :virtual public Base{private:int r;public:Circle();Circle(int x,int y,int r);void draw();};class Graphics :public Poit,public Line, public Circle{private:static int i;void (*pf[6])();public:void task(Poit *p); void task(Line *l);void task(Circle *c);void draw();};int Graphics::i=0;#include <iostream.h>#include "Graphics.h"Base::Base(){x=0;y=0;}Base::Base(int x,int y){this->x=x;this->y=y;}void Base::move(){cout<<"將畫筆移動到("<<x<<","<<y<<"),";}Poit::Poit():Base(0,0){}Poit::Poit(int x,int y):Base(x,y){}void Poit::draw(){Base::move();cout<<"畫一個(gè)點(diǎn)"<<endl;}Line::Line():Base(0,0){a=0;b=0;}Line::Line(int a,int b,int x,int y):Base(x,y){this->a=a;this->b=b;}void Line::draw(){Base::move();cout<<"畫一條到("<<a<<","<<b<<")的直線"<<endl;}Circle::Circle():Base(0,0){r=0;}Circle::Circle(int x,int y,int r):Base(x,y){this->r=r;}void Circle::draw(){Base::move();cout<<"畫一個(gè)半徑"<<r<<"的圓"<<endl;}void Graphics::draw(){int n;for(n=0;n<i;n++){cout<<"第"<<n<<"步:";(*pf[i])();}}void Graphics::task(Poit *p){pf[i]=p->draw;}void Graphics::task(Line *l){pf[i]=l->draw;}void Graphics::task(Circle *c){pf[i]=c->draw;}#include <iostream.h>#include "Graphics.h"int main(){Graphics g;g.task(new Poit(3,5));return 0;}
查看完整描述

2 回答

?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊

#include <stdio.h>
void print(char *srt)
{
printf("%s\n",srt);
}
void (*p)(char *str);//函數(shù)指針
int main()
{
p=print;//把要指向的函數(shù)給函數(shù)指針
p("Hello World!");//傳進(jìn)參數(shù)
return 0;
}
//簡單例子

查看完整回答
反對 回復(fù) 2021-07-29
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

void (*array[10])(void)
array[10]--->就是函數(shù)指針數(shù)組
將對應(yīng)的函數(shù)名賦值給數(shù)組就可以了

比如這么個(gè)函數(shù)
int fun(int a)

array[0] = fun;
就這樣就可以了。
你試試吧



查看完整回答
反對 回復(fù) 2021-07-29
  • 2 回答
  • 0 關(guān)注
  • 460 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號