怎么做 [英] How to do that

查看:71
本文介绍了怎么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有两个类FooA和FooB使用完全相同的方法。

在我的应用程序中我读了一个INI文件而我应该是实例化

FooA或FooB。(实际上FooA和FooB

代表控制两个不同智能卡读卡器的类,但具有相同的

方法) 。


class FooA

{

int Init();

int Close();

}


class FooB

{

int Init();

int关闭();

}


Myapp

-------

void * pPointer = NULL;

CIni ini; //读取ini文件的类


ini.ReadIni()//读取ini文件

如果ini.GetType == FooA

pPointer = new FooA

else

pPointer = new FooB


pPointer-> Init()

pPointer->关闭()


我尝试通过将pPointer声明为void指针来实现它,但它没有
编译。

我该怎么办?


Hello,

I have two classes FooA and FooB with exactly the same methods.
In my application I read a INI File and I am supposed to instantiate either
FooA or FooB.(Actually FooA and FooB
represents classes to control two differents smart card reader but with same
methods).

class FooA
{
int Init();
int Close();
}

class FooB
{
int Init();
int Close();
}


Myapp
-------
void *pPointer = NULL;
CIni ini; // Class to read a ini file

ini.ReadIni() // read ini file
IF ini.GetType == FooA
pPointer = new FooA
else
pPointer = new FooB

pPointer->Init()
pPointer->Close()

I try to do it by declaring pPointer as a void pointer but it didn''t
compile.
How can I do that ??



推荐答案

Vince写道:
Vince wrote:
你好,

我有两个类FooA和FooB,方法完全相同。


找到给他们一个共同基类的理由。

在我的应用程序中,我读了一个INI文件,我应该实例化
FooA或FooB。(实际上FooA和FooB
表示控制两个不同的智能卡读卡器但使用
相同方法的类)。


工厂模式。获取书籍/设计模式/并在您编码或再次发布之前阅读整个内容



void * pPointer = NULL;
CIni ini; //读取ini文件的类

ini.ReadIni()//读取ini文件
如果ini.GetType == FooA
pPointer = new FooA
else
pPointer = new FooB

pPointer-> Init()
pPointer->关闭()

我尝试通过声明pPointer来做到这一点作为一个无效指针,但它没有编译。
我怎么能这样做?
Hello,

I have two classes FooA and FooB with exactly the same methods.
Find a reason to give them a common base class.
In my application I read a INI File and I am supposed to instantiate either FooA or FooB.(Actually FooA and FooB
represents classes to control two differents smart card reader but with same methods).
Factory Pattern. Get the book /Design Patterns/ and read the entire thing
before you code or post again.
void *pPointer = NULL;
CIni ini; // Class to read a ini file

ini.ReadIni() // read ini file
IF ini.GetType == FooA
pPointer = new FooA
else
pPointer = new FooB

pPointer->Init()
pPointer->Close()

I try to do it by declaring pPointer as a void pointer but it didn''t
compile.
How can I do that ??




你重新发现了抽象的需要基类。在你的教程

中查找它们。


FooA和FooB必须继承一个公共类;然后pPointer可以输入那个

类。


您还重新设计了Factory Pattern,这样您就可以开始阅读了。

-

Phlip
http://industrialxp.org/community/bi...UserInterfaces


class FooA
{
int Init();
int Close();
}
类FooB
{
int Init();
int关闭();
}


那不会编译。你必须投入;在课程定义之后。你必须

指定公共 (默认为私人):


class FooA

{

public:


int Init();

int关闭();

};


class FooB
{

public:


int Init();

int Close();

};


Myapp
-------
void * pPointer = NULL;
CIni ini; //读取ini文件的类


我认为应该是这样的:


CIni ini(" blah.ini") ;


ini.ReadIni()//读取ini文件
如果ini.GetType == FooA


好​​神在哪里做我开始了吗?


Google fortypeid。


这个语法应该是:


if(ini.GetType()==


(假设GetType是一个函数)


pPointer = new FooA
其他
pPointer = new FooB

pPointer-> Init()
pPointer->关闭()
class FooA
{
int Init();
int Close();
}

class FooB
{
int Init();
int Close();
}
That won''t compile. You must put in a ; after a class definition. You must
specify "public" (The default is "private"):

class FooA
{
public:

int Init();
int Close();
};

class FooB
{
public:

int Init();
int Close();
};

Myapp
-------
void *pPointer = NULL;
CIni ini; // Class to read a ini file
I presume that should be something like:

CIni ini("blah.ini");

ini.ReadIni() // read ini file
IF ini.GetType == FooA
Good God where do I start?

Google for "typeid".

Also that syntax should be:

if (ini.GetType() ==

(assuming "GetType" is a function)

pPointer = new FooA
else
pPointer = new FooB

pPointer->Init()
pPointer->Close()




pPointer-> Init();

pPointer->关闭();


坚持一切;在一切之后。


你有很多学习的事情!

-JKop



pPointer->Init();
pPointer->Close();

Stick a ; after everything.

You''ve a lot of learning to do!
-JKop


Heu我想这样做更简单,但我知道这一切。我的问题不是一个

语法,因为

我已经用C / C ++编程了3年s。

通常我只从C ++中拿出我想念的C:模板,继承,

封装。

但是直到这个项目我没有不需要使用抽象类。

无论如何,谢谢


" JKop" < NU ** @ NULL.NULL> écritdansle message de news:

rx ******************* @ news.indigo.ie ...
Heu I wanted to do it simpler but I know all that. My problem is not a
syntax one because
I am already programing in C/C++ for 3 years.
Usually I only take from C++ what I miss from C : template, inheritage,
encapsulation.
But until this project I didn''t need to use abstract class.
Thanks anyway

"JKop" <NU**@NULL.NULL> a écrit dans le message de news:
rx*******************@news.indigo.ie...
类FooA
{init /();
int关闭();
}
类FooB
{init /();
int关闭();
}
class FooA
{
int Init();
int Close();
}

class FooB
{
int Init();
int Close();
}



那不会编译。你必须投入;在课程定义之后。您必须指定公开 (默认为私有):

类FooA
{
公开:

int Init();
int关闭();
};

类FooB
{
公开:

int Init();
int Close( );
};



That won''t compile. You must put in a ; after a class definition. You must
specify "public" (The default is "private"):

class FooA
{
public:

int Init();
int Close();
};

class FooB
{
public:

int Init();
int Close();
};

Myapp
-------
void * pPointer = NULL;
CIni ini; //读取ini文件的类
Myapp
-------
void *pPointer = NULL;
CIni ini; // Class to read a ini file



我认为应该是这样的:

CIni ini(blah.ini);



I presume that should be something like:

CIni ini("blah.ini");

ini.ReadIni()//读取ini文件
如果ini.GetType == FooA
ini.ReadIni() // read ini file
IF ini.GetType == FooA



好神在哪里做我开始了吗?

Google fortypeid。

此语法应该是:

if(ini.GetType()==

(假设GetType是一个函数)



Good God where do I start?

Google for "typeid".

Also that syntax should be:

if (ini.GetType() ==

(assuming "GetType" is a function)

pPointer = new FooA

pPointer = new FooB

pPointer->初始化()
pPointer->关闭()
pPointer = new FooA
else
pPointer = new FooB

pPointer->Init()
pPointer->Close()



pPointer-> Init();
pPointer->关闭();

坚持一切;在一切之后。

你有很多学习要做的事情!

- JKop



pPointer->Init();
pPointer->Close();

Stick a ; after everything.

You''ve a lot of learning to do!
-JKop



这篇关于怎么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆