简体   繁体   中英

Struct definition in a cpp header file not working

data.h

namespace Data{
    class Enviroment{
        private:
            struct EnviromentData {
                float temprature;
                float pressure;
                float light;
            };            

        public:
            float ReturnTemprature();
            float ReturnPressure();
            float ReturnLight();

            void SetTemprature(float);
            void SetPressure(float);
            void SetLight(float);

            void SetAll(float, float, float);
    };
};

data.cpp

#include "data.h"

struct EnviromentData envData;

float ReturnTemprature(){
    return envData.temprature;
}
    
float ReturnPressure(){
    return envData.pressure;
}

float ReturnLight(){
    return envData.light;
}

void Set(float temprature, float pressure, float light){
    envData.temprature = temprature;
    envData.pressure = pressure;
    envData.light = light;
}

On the line struct EnvirometnData envData; I have the

error Variable has incomplete type 'struct EnviromentData'

I'm not sure what I have done wrong, my implementation is based of the top answer to this stackover question

You should supply the namespace(Data::Enviroment::EnviromentData) and make EnviromentData public.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM