类的结构 [英] structures with classes

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

问题描述

大家好

我想在类中使用结构

我做的方式是

HI all

i want to use structure inside the class

The way i did is

testStruct.h

class testStruct
{


public:  struct msvq_param {         /* Multistage VQ parameters */
             int num_stages;
             int *num_levels;
             int *num_bits;
             int dimension;
             int num_best;
             int *indices;
             char *fname_cb;
             double *cb;
         };

};









and in thetestStruct.cpp
i create object of class

testStruct testStructObj;


where ever structure is used i apply   testStructObj.msvq_param



但它不能正常工作

请在类旁边指导如何在头文件中使用结构

然后通过创建其对象,我可以通过添加头文件在任意位置使用它
在该.cpp文件中

请帮助

问候

Saima



but its not working properly

kindly guide how to use structure inside header file in side the class

and then by creating its object i can use its any where by adding header file
in that .cpp file

plz Help

Regards

Saima

推荐答案

您可能想在您的类中分配该结构的成员,例如:
You probably want to allocate a member of that structure in your class, for example by:

class testStruct
{
public:  
    struct msvq_param {         /* Multistage VQ parameters */
             int num_stages;
             int *num_levels;
             int *num_bits;
             int dimension;
             int num_best;
             int *indices;
             char *fname_cb;
             double *cb;
         } m_param;
};


然后,您可以通过(示例)访问该成员


Then you can access that member by (example)

testStructObj.m_param.stages = ...



或者您只想访问结构定义.然后,您将必须编写:



Or your just want to access the structure definition. Then you would have to write:

testStruct::msvq_param   myParam;


报价:

testStructObj.msvq_param

testStructObj.msvq_param


或者更正确地


or rather correctly

报价:

testStructObj :: msvq_param

testStructObj::msvq_param


是一种访问msvq_param声明的方法

要利用此结构,您应该为此结构使用一个变量,您可以将其作为类的受保护/私有成员使用


is a way to access the declaration of msvq_param

To utilize this structure, you should have a variable for this structure, which you can have as a protected/private member of your class


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

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