Click here to Skip to main content
12,404,278 members (72,644 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VC6 C++
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

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
Posted 1-May-12 22:46pm
prog786457
Comments
CPallini 2-May-12 6:20am
   
What do you mean with 'it is not working properly'?
Please elaborate.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Quote:
testStructObj.msvq_param

or rather correctly
Quote:
testStructObj::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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 2 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100