NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Compiler Error C2354

'reference' : initialization of reference member requires a temporary variable

A constructor initializes a reference to a member instead of initializing the member.

It is illegal to initialize a reference member of a class in the class's constructor with a temporary variable. An attempt to do so generates the C2354 error, as illustrated by this sample code:

   int temp() { return 1; }

   class Test
   {
   public:
       int member;
       int& ref_member;
       Test();
   };

   Test::Test() : ref_member( temp() )
   {
   }

When this error is encountered, the solution is to change the code so that the reference member is not initialized to a temporary variable. The reference must be initialized to an object that will exist for the lifetime of the reference member.