Cant use class in another one.

This is a discussion on Cant use class in another one. within the C++ Programming forums, part of the General Programming Boards category; Hi all,i hope someone can figure out whats stupid with this programme.I have a class which is for point in ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    18

    Cant use class in another one.

    Hi all,i hope someone can figure out whats stupid with this programme.I have a class which is for point in 2D which works quite good. And i want to create another class for vectors which should use point class on it. The class i wrote:

    Code:
    #ifndef TVECTOR_H_
    #define TVECTOR_H_
    
    //#include <cmath>
    #include <math.h>
    #include "TPoint2D.h"
    #define PI 3.14159265
    
    class TVector
    {
    public:
    
                    TVector();
                    TVector(TPoint2D , TPoint2D );
                    TPoint2D const TVector::PointA() ;
                    TPoint2D const TVector::PointB() ;
    
     private:
    
                    TPoint2D pointA_,pointB_;
    
    };
    
    TVector::TVector()
    {
    	TPoint2D pointA_ = TPoint2D();
    	TPoint2D pointB_ = TPoint2D();
    }
    
    
    TVector::TVector(TPoint2D pointA, TPoint2D pointB)
    {
    	pointA_ = pointA;
    	pointB_ = pointB;
    
    }
    
    
    
    TPoint2D const TVector::PointA() ;
    {
    	return pointA_;
    }
    
    
    TPoint2D const TVector::PointB() ;
    {
    	return pointB_;
    }
    
    #endif /*END OF TVECTOR_H_*/

    And the errors i get:

    PHP Code:
    TVector.h:47errordeclaration of `const TPoint2D TVector::PointA()' outside of class is not definition
    TVector.h:48: error: expected unqualified-id before '{' token
    TVector.h:48: error: expected 
    `,' or `;' before '{' token
    TVector
    .h:54errordeclaration of `const TPoint2D TVector::PointB()' outside of class is not definition
    TVector.h:55: error: expected unqualified-id before '{' token
    TVector.h:55: error: expected 
    `,' or `;' before '{' token 
    and here how i declare my point class:

    Code:
    #ifndef TPOINT2D_H_
    #define TPOINT2D_H_
    
    //#include <cmath>
    #include <math.h>
    #define PI 3.14159265
    
    class TPoint2D
    {
    public:
    
                   TPoint2D();
                   TPoint2D(double coord1 , double coord2 );
                   double Distance(TPoint2D pointA, TPoint2D pointB);
                   void Topla(TPoint2D pointA, TPoint2D pointB, TPoint2D &pointC);
                   double Ro(TPoint2D pointA);
                   double Phi(TPoint2D TpointA);
                   double  const TPoint2D::Coord1();
                   double  const TPoint2D::Coord2();
    
    
     private:
    
                   double coord1_,coord2_;
    
    };
    
    
    TPoint2D::TPoint2D()
    {
                  coord1_ = 0.0;
                  coord2_ = 0.0;
    
    }
    
    
    
    
    TPoint2D::TPoint2D(double coord1,double coord2)
    {
                   coord1_ = coord1;
                   coord2_ = coord2;
    
    }
    
    
    
    
    double const TPoint2D::Coord1()
    {
    	return coord1_;
    }
    
    
    
    double  const TPoint2D::Coord2()
    {
    	return coord2_;
    }


    Thanks in advance and sorry for wasting time

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> TPoint2D const TVector::PointA() ;
    That semicolon shouldn't be there.

  3. #3
    #define WORLD "sad place" LinuxCoder's Avatar
    Join Date
    Mar 2006
    Location
    Portugal
    Posts
    89
    >> TPoint2D const TVector::PointA() ;
    That semicolon shouldn't be there.
    The same applies to
    Code:
    TPoint2D const TVector::PointB() ;
    I have one question regarding those declarations. Is there any difference between:
    Code:
    TPoint2D const TVector::PointB()
    and:
    Code:
    const TPoint2D TVector::PointB()
    I ask this because i remember reading something about that being different when using pointers. From what i remember reading the following three declarations are all different:
    Code:
    const char *ptr;
    char* const ptr;
    const char* const ptr;
    Sorry about asking this in this thread but these questions just came from the thread.

    Thanks and cheers.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Thanks Daved i would spend another hour on it to realize that.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    These are the same:
    Code:
    TPoint2D const TVector::PointB()
    const TPoint2D TVector::PointB()
    However this is not:
    Code:
    TPoint2D TVector::PointB() const
    The const after the function name specifies that the function doesn't modify the calling object.

    For pointers:
    Code:
    int foo = 0;
    const int* ptr1 = &foo; //value pointed to cannot change
    const int* const ptr2; //value and pointer can't change
    *ptr1 = 5; //error
    ptr1 = ptr2; //ok
    ptr2 = ptr1; //error
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 11:36 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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