Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4058154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:02:37+00:00 2026-05-20T15:02:37+00:00

I have a class. I have made two seperate files, the header, and the

  • 0

I have a class. I have made two seperate files, the header, and the c++ file. I am using it to create a more-or-less Light ‘object’ for an opengl game I am working on. Here are the files:
Light.h

#ifndef LIGHT_H
#define LIGHT_H


class Light
{
    public:
        Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex);
        virtual ~Light();
        float x,y,z;
        int index;
        int type;
        struct ambient
        {
            float r, g, b, a;
        };
        struct diffuse
        {
            float r, g, b, a;
        };
        struct specular
        {
           float r, g, b, a;
        };
    protected:
    private:
};

#endif // LIGHT_H

and, Light.cpp

#include "../include/Light.h"

Light::Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex)
{
    index=iindex;
    type=itype;
    x=ix;
    y=iy;
    z=iz;
    ambient.r = 0.2;
    ambient.g = 0.2;
    ambient.b = 0.2;
    ambient.a = 1.0;
    specular.r = 0.8;
    specular.g = 0.8;
    specular.b = 0.8;
    specular.a = 1.0;
    diffuse.r = ir;
    diffuse.g = ig;
    diffuse.b = ib;
    diffuse.a = ia;
}

Light::~Light()
{
    //dtor
}

When I try to compile, it throws an error saying:
error: expected unqualified-id before ‘.’ token|
For every line where I assign a value to a member of the structs (ambient, diffuse, specular)
First off, I can’t even interpret this error. No clue what it means. Secondly, I fail to see what I am doing wrong. Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:02:38+00:00Added an answer on May 20, 2026 at 3:02 pm

    This should read so:

    #ifndef LIGHT_H
    #define LIGHT_H
    
    
    class Light
    {
        public:
            Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex);
            virtual ~Light();
            float x,y,z;
            int index;
            int type;
            struct
            {
                float r, g, b, a;
            } ambient;
            struct
            {
                float r, g, b, a;
            } diffuse;
            struct
            {
               float r, g, b, a;
            } specular;
        protected:
        private:
    };
    
    #endif // LIGHT_H
    

    The basic problem is that you were declaring that the structs existed and giving the name of the type, but you weren’t declaring any variables of that type. Since, from your usage, it was clear that the type of these structs didn’t need a name (they could be anonymous structs) I moved the name after the declaration so you were declaring a variable instead.

    As GMan pointed out, this is still not optimal. Here is a better way to go about this:

    #ifndef LIGHT_H
    #define LIGHT_H
    
    
    class Light
    {
        public:
            Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex);
            virtual ~Light();
            float x,y,z;
            int index;
            int type;
    
            struct Color {
                float r, g, b, a;
            };
    
            Color ambient, diffuse, specular;
        protected:
        private:
    };
    
    #endif // LIGHT_H
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class, Number , which represents a double with two digits after
I have a class which models online campaigns i.e. people clicking through to the
A hatch pattern is made from two colors: one defined by the BackgroundColor, which
I've made a class (code below) that handles the creation of a matching quiz
I've got two forms. In the first, I have a textbox and a button,
hi i am using mootool.js and i want to use two buttons (show/hide).There is
I have been using a custom type for Money with my POCOs and tries
Hey, I have a question regarding code structure, and was wondering what the best
I have implemented a Facebook Like button into my site. I wanted to make
I have a map that is cut up into a number of regions by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.