开发者

how to declare variables in class?

I have following code:

class one
{
public:
  typedef int (*funPtr) (void);
  one()
  {
    // here I'm u开发者_如何学Csing map variable which is private. 
  }
  ~one(){}

private:
  typedef map<int, funPtr> mMap;
  mMap mapVar;  
};

In this case class constructor gives that error that map is not declared. Can anyone help me?


A typedef defines a type...basically an aliasing...if you wish to declare a variable mMap of type map you would just do

map mMap;


For the compiler to know what map is, the typedef for map should be placed before first usage.


You're not declaring a variable anywhere.

You would need to use the typedef to declare an actual variable:

typedef map<int, funPtr> mMap;
mMap myMap;

I suspect you're not meaning to use typedef at all, and simply need to be doing:

map<int, funPtr> mMap;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜