-2

I am a very new guy to visual studio as well as IDL. I have an .idl file and visual studio is generating .h and .cpp files from the idl file.

In the generated code , a "const" is addded for "in" attribute in IDL file. I want to get rid of this "const"...please somebody help me.

generated header file has the following functions:

virtual CosTransactions::Coordinator_ptr recreate(
                    const CosTransactions::PropagationContext& ctx,
                    CosTransactions::otid_t_out tid) = 0;

virtual CosTransactions::Coordinator_ptr tmf_start(
                   const CosTransactions::otid_t& tid) = 0;

I would like to know how to avoid the "const" in the parameter list of recreate() and tmf_start()

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
whitetiger
  • 412
  • 1
  • 4
  • 13
  • 2
    Do you understand why it is there? Do you understand how you break the contract if you remove it? Why do you need to remove it? Why don't you work around this "limitation" instead? – Magnus Hoff Jul 08 '13 at 10:58
  • The actual problem is that , I am porting my code from an older C++ compiler to new compiler. I see that I cannot use stl::map in new compiler. The key type cannot be const in stl::map in new compiler. When doing this change , I had to change many related functions also. Finally I reached the point where code is generated from IDL file.... – whitetiger Jul 08 '13 at 11:08
  • On the face of it, it sounds like you should be asking details about how to use `std::map` instead. Having a `const&` parameter here sounds like exactly the right thing. – Magnus Hoff Jul 08 '13 at 11:20

1 Answers1

1

Since the parameter itself is [in] no changes of the parameter will be taken any further. This is why const makes sense in first place. You did not explain why at all you would want to strip the constness. If the specifier is an obstacle for you (e.g. an inner method takes non-const & as an argument), there are two simple and straightforward ways to work it around:

  1. const_cast to strip/override the const specifier
  2. a local stack copy of the context for further manipulation
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • if I change the const-ness of this parameter in the derived classes, that implementation method will get detached from the polymorphic hierarchy! – whitetiger Jul 08 '13 at 11:10