I'm an experienced programmer of 5 years in Java & C#, but recently I decided to program in C++ as well. I'm familiar with proper code syntax and advanced programming techniques, but this compiler error i'm getting just stumps me beyond recognition, I've analyzed my code for syntax errors a hundredfold and I simply don't see a fault in it.

The compiler generates 'fatal error C1004: unexpected end-of-file found'.

This is a wrapper for a Direct3D D3DCOLOR.
Code snippet(color.cpp):

//-----------------------------------------------------------------------------
//
//	Copyright (C) Gamerbros Entertainment.  All Rights Reserved.
//
//-----------------------------------------------------------------------------

#pragma comment(lib,"d3d9.lib")
#include <d3d9.h>

typedef unsigned char byte;
//-----------------------------------------------------------------------------
//	(class)Color definition
//-----------------------------------------------------------------------------
class Color{
private:
    byte a, r, g, b;
    Color(){}

public:
    // Constructor with all red, green, blue, and alpha values set to separate values.
    Color(byte alpha, byte red, byte green, byte blue){ setColor(alpha, red, green, blue); }
    // Constructor with red, green, and blue values set to separate values. Alpha is 255.
    Color(byte red, byte green, byte blue){ setColor(255, red, green, blue); }
    // Constructor with red, green, and blue values set by a single value, and alpha set separately.
    Color(byte alpha, byte value){ setColor(alpha, value, value, value); }
    // Constructor with red, green, and blue values set by a single value.
    Color(byte value){ setColor(value, value, value, value); }
    // Constructor with color values set by a color, and alpha set separately.
    Color(Color color, byte alpha){ setColor(alpha, color.r, color.g, color.b); }
    // Constructor with red, green, and blue values set by a D3DCOLOR value.
    Color(D3DCOLOR color){ setD3DColor(color); }

    // Sets this colors values to the values of the new color.
    void setColor(Color color){
        setColor(color.a, color.r, color.g, color.b;);
    }
    // Sets the alpha, red, green, and blue values of this color.
    void setColor(byte alpha, byte red, byte green, byte blue){
        a = alpha;
        r = red;
        g = green;
        b = blue;
    }
    // Gets the alpha value of this color.
    byte getAlpha(){ return a; }
    // Sets the alpha value of this color.
    void setAlpha(byte alpha){ a = alpha; }
    // Gets the red value of this color.
    byte getRed(){ return r; }
    // Sets the red value of thie color.
    void setRed(byte red){ r = red; }
    // Gets the green value of this color.
    byte getGreen(){ return g; }
    // Sets the green value of this color.
    void setGreen(byte green){ g = green; }
    // Gets the blue value of this color.
    byte getBlue(){ return b; }
    // Sets the blue value of this color.
    void setBlue(byte blue){ b = blue; }
    // Gets a D3DCOLOR copy of this color.
    D3DCOLOR getD3DColor(){ return D3DCOLOR_ARGB(a, r, g, b); }
    // Sets the values of this color based on a D3DCOLOR
    void setD3DColor(D3DCOLOR d3DColor){
        a = d3DColor >> 24;
        r = (d3DColor >> 16) & 0xFF;
        g = (d3DColor >> 8) & 0xFF;
        b = d3DColor & 0xFF;
    }
    // Gets a gradient of a percentage of this color and another.
    Color getFromGradient(Color to, float percentage){ return createGradient(*(new Color(a, r, g, b)), to, percentage); }
    // Sets this color to a gradient of a percentage of two colors.
    void setFromGradient(Color from, Color to, float percentage){ setColor(createGradient(from, to, percentage)); }

    // Creates a gradient of a percentage of two colors.
    Color createGradient(Color from, Color to, float percentage){
        byte red = (byte)(from.r + (percentage * (to.r - from.r)));
        byte green = (byte)(from.g + (percentage * (to.g - from.g)));
        byte blue = (byte)(from.b + (percentage * (to.b - from.b)));

        return *(new Color(red, green, blue));
    }
}

Originally this was split into a header and source file, with class Color being declared in the header and defined in the source.
I removed that to simplify this post.

Any clear help will be very appreciated, and special thanks to the experts and professionals that take the time to look at an amateur c++ programmers problem.

Edited 6 Years Ago by batchprogram: n/a

Hmm, well make sure that "d3d9.h" includes #endif if there is #ifndef

The problem might be that you are not using include guards and are accidentally including either the .h or .cpp file twice.

Also, you should add a blank line to the end of each of your files (some old systems/compilers require this to my knowledge).

Your class is missing a ; after the closing }

I didn't notice that, but yeah, that is important too!

Haha... I didn't know that c++ classes required a semicolon after the ending right curly brace.

Thanks Salem and CppFTW, and yes the header file does have an include guard. I rebuilt the code and it compiled successfully.

Oh, okay, but just make sure that your .cpp also has an include guard (I don't see it in the code snippet).

Haha... I didn't know that c++ classes required a semicolon after the ending right curly brace.

One of the idiosynchracies of the language.
And of course you get an unexpected end of file if it's not there and the file ends :)

This question has already been answered. Start a new discussion instead.