error C3076: you cannot embed an instance of a reference type, 'BasicCamera', in a native type


  • I borrow the code file 'BasicCamera.h/cpp' from Windows 8 code sample, Direct3D tutorial in my project. The definition of BasicCamera is defined as

    #pragma once
    #include "BasicMath.h"
    // a simple camera class
    ref class BasicCamera
       void GetViewMatrix(float4x4 *viewMatrix);
       void GetProjectionMatrix(float4x4 *projectionMatrix);
       // Update the view matrix based on new position and focus coordinates
       void SetViewParameters(
            const float3& eyePosition,    // the position of the camera
            const float3& lookPosition,   // the point the camera should look at
            const float3& up              // the durection vector for up
       // Update the perspective projection matrix based on new parameters
       void SetPerspectiveProjection(
            float minimumFieldOfView,  // the minimum horizontal or vertical field of view, in degrees
            float aspectRatio,         // the aspect ratio of the projection (width / height)
            float nearPlane,           // depth to map to 0
            float farPlane             // depth to map to 1
       float3 m_position;      // the position of the camera
       float3 m_direction;     // the unit vector of the viewing direction
       float4x4 m_view;        // view matrix
       float4x4 m_projection;  // projection matrix

    Another class makes use of BasicCamera:

    class mgral_directx { public: // Irrelevant definitions omitted // ...... private:

    BasicCamera camera; // error C3076


    I am also unclear about what is a reference type, and what is a native type. Do they differ in the presence (absence) of the modifier "ref"?

    Sunday, July 22, 2012 8:22 AM


  • For more info on ref types, see http://msdn.microsoft.com/en-us/library/windows/apps/hh699870(v=vs.110).aspx


    Thanks Nishant. I read the document. Is it correct to say a reference class/struct should always be declared with a handle-to-object operator ^?

    Well in a manner of speaking, I'd say yes, the hat needs to be used to indicate that this is a ref-counted object. But the C++ team have also implemented stack semantics (compiler magic that lets you avoid using the ^). Right now this only seems to work for locals - for class members, they don't seem to have implemented it yet. So for now, it'd be best if you just always used a ^.

    [Note: even with stack semantics, the generated code is the same. The compiler magic lets you treat it as if it were a non-^ local/member, that's all]


    • Marked as answer by Leonard Monday, July 23, 2012 4:48 PM
    Monday, July 23, 2012 3:18 PM

All replies