class member construction with parameter

I am using MFC, and I want to add a named CEvent class member to my Dialog class, in public.

this code is fine.
CEvent RILResultEvent;

but this is not
CEvent RILResultEvent(FALSE,FALSE,L"HELLO");

how can I put parameters to the constructor? maybe I can declare a pointer to CEvent and create and free it manually, or someone else suggested to put it in initialization list. but using a initialization list means I have to put the constructor to class declaration? which is in header file. personally I don't like to write code in header file. moreover MFC already created the constructor in .cpp file.

any hint?

class myDialog: public CDialog
{
public:
CEvent RILResultEvent(FALSE,FALSE,L"HELLO"); //error
};


CEvent RILResultEvent(FALSE,FALSE,L"HELLO"); is a function
call and is not allowed in a calss declaration.
Construct the CEvent in the initialisation list - as you say
MFC already created the constructor for your dialog in .cpp file.
- so you will have to modify the dialog constructor in the cpp file to add initialisation for the CEvent RILResultEvent object.


Last edited on
i am talking about the design of C++ language here,

i thought a default constructor is also a constructor, and my parameters are static so they should be treated the same.
moreover, the actual default constructor can also call another constructor with predefined parameter anyway.....

seems the only solution is like what you say, move the default constructor to CPP file.
thanks for your help
Topic archived. No new replies allowed.