Porting from g++ to VC6

This is a discussion on Porting from g++ to VC6 within the Windows Programming forums, part of the Platform Specific Boards category; Hello! I'm presently trying to port a school project from g++ to VC and I'm having a few problems. Right ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    32

    Porting from g++ to VC6

    Hello! I'm presently trying to port a school project from g++ to VC and I'm having a few problems. Right now I'm trying to port a simple vector class.

    #include <stdio.h> //sprintf
    #include <math.h>
    #include <iostream.h>
    #include <limits.h>

    class vector2 {
    public:
    ...constructors
    ...class functions

    //For input and output
    istream &input(istream &is) {
    is.ignore(INT_MAX,'(');
    is >> x;
    is.ignore(INT_MAX,',');
    is >> y;
    is.ignore(INT_MAX,')');
    return is;
    }
    };

    this generates errors:

    >syntax error : missing ';' before '&'
    >'istream' : missing storage-class or type specifiers

    Are there a lot of differences in syntax within class declarations in VC compared to g++?

    Do I have to tell the linker to include the math library somhow?

    Well, any help is appreciated

    If you know of any web pages dealing with moving from gcc&g++ to MSVC feel fre to point me to em

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,649
    What you have posted compiles fine for me (in VC++ 6.0). You will have to post more code or post the exact compiler error including line #'s (and the code on those lines).

    gg

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    32
    Opps should've tried that myself before I posted...doh

    Anyway..this is the entire vector class

    Below is a sample cpp file and the entire vectorclass.

    Thank you very much for taking your time with this btw.

    /*--------------------------------------------------
    Sample.cpp FRAX
    --------------------------------------------------*/
    #include "vector2.h"

    void main()
    {
    vector2 v2TestVector1(0.1,0.4);
    return;
    }



    And this is the vector class


    /////////////////////////////////////////////////////////////////////////////
    // Filename: vector2.h
    // Description: 2D vector class
    /////////////////////////////////////////////////////////////////////////////

    #ifndef __vector2_h
    #define __vector2_h

    #include <stdio.h> //sprintf
    #include <math.h> //sqrt[abs],acos[angle]
    #include <iostream.h>
    #include <limits.h>

    class vector2 {
    public:
    float x,y;

    public:
    vector2():x(),y() {}
    vector2(float xx,float yy):x(xx),y(yy) {}
    vector2(const vector2 &v):x(v.x),y(v.y) {}

    // [] operator to get elements
    float &operator [](int i) {return (&x)[i];}
    const float &operator [](int i) const {return (&x)[i];}

    //assignment operator
    vector2 &operator =(const vector2 &v) {x=v.x; y=v.y; return *this;}

    //relation operators
    bool operator ==(const vector2 &p) const {return ((x==p.x)&&(y==p.y));}
    bool operator !=(const vector2 &p) const {return !((*this)==p);}

    //simple arithmetics
    vector2 &operator+=(const vector2 &p) {x+=p.x;y+=p.y;return *this;}
    vector2 operator + (const vector2 &p) const {return vector2(x+p.x,y+p.y);}

    vector2 &operator-=(const vector2 &p) {x-=p.x;y-=p.y;return *this;}
    vector2 operator - (const vector2 &p) const {return vector2(x-p.x,y-p.y);}
    vector2 operator - () const {return vector2(-x,-y);}

    vector2 &operator*=(float f) {x*=f;y*=f;return *this;}
    vector2 operator * (float f) const {return vector2(x*f,y*f);}

    vector2 &operator/=(float f) {x/=f;y/=f;return *this;}
    vector2 operator / (float f) const {return vector2(x/f,y/f);}

    //scalar product
    float operator * (const vector2 &v2) const {return x*v2.x+y*v2.y;}

    //z component of vector product
    float operator ^ (const vector2 &v2) const {return x*v2.y-y*v2.x;}

    //abs by definition
    float abs() const {return sqrt((*this)*(*this));}

    //For input and output

    istream &input(istream &is) {
    is.ignore(INT_MAX,'(');
    is >> x;
    is.ignore(INT_MAX,',');
    is >> y;
    is.ignore(INT_MAX,')');
    return is;
    }

    virtual ostream &output(ostream &os) const {
    os.precision(3);
    os << "vector2(" << x << ", " << y << ")";
    return os;
    }

    };


    //wrong order multiply
    inline vector2 operator *(float f, const vector2 &v) {return v*f;}

    inline istream &operator >>(istream &is,vector2 &v) {
    return v.input(is);
    }

    inline ostream &operator <<(ostream &os,vector2 const &v) {
    return v.output(os);
    }


    #endif //__vector2_h

    /////////////////////////////////////////////////////////////////////////////
    // END OF FILE //
    /////////////////////////////////////////////////////////////////////////////

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,649
    Compiles fine for me (apart from a few warnings). Whats not working for you?

    Also, when you post code, use code tags.

    gg

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    32

    Strange

    LOL, what a weird problem this has been. I think it's my VC6 setup that's playing tricks on me.

    I think it might be because I used some strange variant of STLport when I compiled some CVS code earlier. I also installed a new platform SDK and probably messed things up there as well.

    I removed these libraries from my include path but now I seem to get problems with the linker instead of syntax errors.

    Perhaps I should give my computer the stab of death and just reinstall everything.

    Thank you very much for your help. Without it I would never have found this out

    And I'll use the code tags in the future


    Edit: Now it works great, finaly I can continue
    Last edited by Hubas; 03-22-2003 at 08:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Porting from VC6 to Linux Fedora core 5
    By g4j31a5 in forum C++ Programming
    Replies: 17
    Last Post: 08-08-2006, 01:59 AM
  2. using VC6 link VC7 static lib error
    By George2 in forum C++ Programming
    Replies: 5
    Last Post: 06-29-2006, 10:58 PM
  3. VC6 directories
    By Magos in forum Tech Board
    Replies: 0
    Last Post: 03-11-2005, 04:52 PM
  4. boost::serialization + vc6
    By Koyaanisqatsi in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2004, 04:43 PM
  5. Porting to FreeBSD
    By Beastie in forum Linux Programming
    Replies: 1
    Last Post: 06-15-2003, 07:37 PM

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