Need help with error message!

This is a discussion on Need help with error message! within the C++ Programming forums, part of the General Programming Boards category; I am trying to call a constructor from the class RightTriangle, but i get the following error messages: client.cpp(14) : ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    Need help with error message!

    I am trying to call a constructor from the class RightTriangle, but i get the following error messages:

    client.cpp(14) : error C2065: 'RightTriangle' : undeclared identifier
    client.cpp(14) : error C2146: syntax error : missing ';' before identifier 'left_nostril'
    client.cpp(14) : error C2065: 'left_nostril' : undeclared identifier

    I know what the error messages mean. I just understand why i get them. I have triangle.h declared. Here is my client code, triangle.h, and triangle.cpp.

    *************client code********************
    #include "triangle.h"

    enum Direction{NW,NE,SW,SE};
    int main()
    {

    RightTriangle left_nostril(36,7,4,NW); //this is where the 3 errors occur
    return 0;
    }
    ***********triangle.h*******************
    #include "shape.h"
    class RightTriangle : public Shape
    {

    public:
    RightTriangle (int xx,int yy,int ss,int qq);
    private:
    int x;
    int y;
    int s;
    int q;
    };
    ***********triangle.cpp******************
    #include "triangle.h"

    enum Direction{NW,NE,SW,SE};
    Direction d;

    RightTriangle::RightTriangle(int xx,int yy, int ss, int qq)
    {
    x=xx;
    y=yy;
    s=ss;
    q=qq;
    if (q==0)
    d=NW;
    if (q==1)
    d=NE;
    if (q==2)
    d=SW;
    if (q==3)
    d=SE;
    }

    Any help would be appreciated. I can't revise my program anymore until this problem is resolved.

  2. #2
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    you need a prototype for RightTriangle left_nostril(36,7,4,NW);
    the best things in life are simple.

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    post the Shape.cpp file.......your base class.....

    maybe the error is deeply nested...

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    11
    here is the shape class:
    ***********shape.h*********
    class Shape
    {
    public:
    Shape();
    };
    ***********shape.cpp**********
    #include "shape.h" // for Shape class

    using namespace std;

    Shape * Shape::head = NULL; // static variable declaration

    Shape::Shape()
    // Postcondition: this Shape has been added to the list
    {
    next = head ;
    head = this;
    }

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    11
    prototype? i don't follow.

  6. #6
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    by looking at your shape.h......there's nothing there besides the constructor....and inside your shape.cpp you initialize some head and this....

    it doesn't fall in place... you can't initialize something that wasn't declared...

    hope that helps

    Regards,
    matheo917

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21