type: 'float' unexpected

Discussion in 'Software' started by longbowrocks, Mar 4, 2010.

  1. longbowrocks

    longbowrocks Private E-2

    I used to have the class definition in a separate header file, but I moved it into the same file as it's constructor to see what was wrong. Despite moving the definition, I'm still getting the same errors:

    error C2062: type 'float' unexpected
    syntax error : missing ';' before '{'
    '{' : missing function header (old-style formal list?)

    all three errors occur on the first line of the constructor implementation. there are no includes or namespaces in my file. Am I doing something obviously wrong?

    class Domino{
    public:
    float x;
    float y;
    float z;
    float x2;
    float y2;
    float z2;
    int state;
    Domino(float a1, float b1, float c1, float a2, float b2, float c2);
    };

    Domino(float a1, float b1, float c1, float a2, float b2, float c2){ <--HERE
    x = a1;
    y = b1;
    z = c1;
    x2 = a2;
    y2 = b2;
    z2 = c2;
    state = 0;
    }
     
  2. Wyatt_Earp

    Wyatt_Earp MajorGeek

    Is there any other text above the constructor implementation? Often, missing semicolon compiler errors show up later than you would expect and don't point to the line where the actual error is. Can you post the rest of the code, if there is more?
     
  3. longbowrocks

    longbowrocks Private E-2

    all that's above is these two include statements:
    #include <GL/glut.h>
    #include <stdio.h>

    all that's below is 800 sets of coordinates for 100 dominos. (8 vertices per domino)
     
  4. SWario

    SWario Sergeant

    Just to be sure, what language is this?
     
  5. Jocko_Homo

    Jocko_Homo Private E-2

    Code:
    Domino(float a1, float b1, float c1, float a2, float b2, float c2) {
    	x = a1;
    	y = b1;
    	z = c1;
    	x2 = a2;
    	y2 = b2;
    	z2 = c2;
    	state = 0;
    }
    I haven't compiled this code but one problem I immediately see is that the constructor body definition lacks a namespace qualifier. However, that shouldn't fail to compile. That should simply make a new function that returns an integer, unless you have some funny compiler settings set...

    Incidentally, why does no one use code blocks? Reading unindented code is no fun..
     
  6. Senlis

    Senlis Staff Sergeant

    I fixed it by putting Domino:: in front of the function. This identifies the function with the Domino class. Here is the modified code. I still got an unresolved external build error, but that is probably just because I am missing a file that you have and I don't. See how this works.

    //#include <GL/glut.h> I had to remark this out cause I don't have the file
    #include <stdio.h>

    class Domino{
    public:
    float x;
    float y;
    float z;
    float x2;
    float y2;
    float z2;
    int state;
    Domino(float a1, float b1, float c1, float a2, float b2, float c2);
    private:
    };

    Domino::Domino(float a1, float b1, float c1, float a2, float b2, float c2){
    x = a1;
    y = b1;
    z = c1;
    x2 = a2;
    y2 = b2;
    z2 = c2;
    state = 0;
    }
     
  7. longbowrocks

    longbowrocks Private E-2

    I can't believe I forgot such a critical piece of information. this is C++. Not Java, not C#, and definitely not SPARTA.
    Also, sorry about the lack of indentations. Generally I have them in my code, but when I need help I try to copy out small enough sections that people can see what's wrong without needing to scan dozens or hundreds of lines. This section was missing indents because I've gotten used to Visual Studio indenting for me, and this was in a header, which it doesn't indent.
    Finally, problem solved by Senlis. Thank you! I've got to ask you though: isn't the scoping operator :):) reserved for referencing things within an actual namespace? Why did that work?
     
  8. Jocko_Homo

    Jocko_Homo Private E-2

    It depends on what you mean by "actual namespace." Classes are namespaces. Off the top of my head, I can't think of anything that can be done in a namespace that can't be done in a class definition and they both work the same. For example:
    Code:
    namespace first {
    	int foo;
    }
    
    class second {
    public:
    	static int foo;  // class variable and not an object variable...
    }
    
    first::foo = 1;   // of course this works...
    second::foo = 2;  // but this works too!
    Both classes and namespaces define a named scope that is accessible with the :: operator...
     
  9. longbowrocks

    longbowrocks Private E-2

    Thank you. I think you just explained most of the errors I've ever gotten with C++.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds