Sign in to follow this  
webwraith

Unity Class Chaos (yes, again...:( )

Recommended Posts

webwraith    239
Hi again![embarrass] hopefully, this should be a quick one. After my last thread (Class Chaos ver. 1) I had a fully working vector class. Now the only thing I would like to know is, how do I change my vector to be turned into a static library? This is the vector code: mglvector.h;
#ifndef MGLVECTOR_H
#define MGLVECTOR_H

/************************************
 * mglVector3:- contains x,y, and z *
 *              all are floats      *
 ************************************/

class mglVector3
{
    public:
        mglVector3():x(0.0f),y(0.0f),z(0.0f){}
        mglVector3(float x_,float y_,float z_);
        mglVector3(const mglVector3& mVec);
        ~mglVector3();

        // operators- yay :P XO

        mglVector3& operator=(const mglVector3 mVec);
        mglVector3& operator=(const float array[3]);

        mglVector3& operator+=(const mglVector3& mVec);
        mglVector3& operator+=(const float array[3]);

        mglVector3& operator-=(const mglVector3& mVec);
        mglVector3& operator-=(const float array[3]);

        mglVector3& operator*=(float var);


        /*standard addition operators
          the form this vector+array*/
        friend mglVector3 operator+(const mglVector3& mVec,float array[3])
        {
            return mglVector3(array[0] + mVec.x, array[1] + mVec.y, array[2] + mVec.z);
        }

        //the form array+this vector
        friend mglVector3 operator+(float array[3],const mglVector3& mVec)
        {
            return mglVector3(array[0] + mVec.x, array[1] + mVec.y, array[2] + mVec.z);
        }

        //the form this vector+other vector
        friend mglVector3 operator+(mglVector3 mVec1,const mglVector3& mVec2)
        {
            return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
        }

        //the form other vector+this vector
        friend mglVector3 operator+(const mglVector3& mVec1,mglVector3 mVec2)
        {
            return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
        }


        /*standard subtraction operators
          the form this vector-array*/
        friend mglVector3 operator-(const mglVector3& mVec,float array[3])
        {
            return mglVector3(mVec.x - array[0], mVec.y - array[1], mVec.z - array[2]);
        }

        //the form array-this vector
        friend mglVector3 operator-(float array[3],const mglVector3& mVec)
        {
            return mglVector3(array[0] - mVec.x, array[1] - mVec.y, array[2] - mVec.z);
        }

        //the form this vector-other vector
        friend mglVector3 operator-(mglVector3 mVec1,const mglVector3& mVec2)
        {
            return mglVector3(mVec1.x - mVec2.x, mVec1.y - mVec2.y, mVec1.z - mVec2.z);
        }

        //the form other vector-this vector
        friend mglVector3 operator-(const mglVector3& mVec1,mglVector3 mVec2)
        {
            return mglVector3(mVec1.x - mVec2.x, mVec1.y - mVec2.y, mVec1.z - mVec2.z);
        }

        //the form this vector*value
        friend mglVector3 operator*(float var,const mglVector3& mVec2)
        {
            return mglVector3(mVec2.x * var, mVec2.y * var, mVec2.z * var);
        }

        //the form value*this vector
        friend mglVector3 operator*(const mglVector3& mVec1,float var)
        {
            return mglVector3(mVec1.x * var, mVec1.y * var, mVec1.z * var);
        }

        float x;
        float y;
        float z;

    protected:
    private:

};


mglvector.cpp;
#include "mglvector.h"

/***********************************
 * mglVector3 overloaded operators *
 *          and methods            *
 ***********************************/

mglVector3::~mglVector3()
{
    // dtor
}

mglVector3::mglVector3(float x_,float y_,float z_)
{
    x=x_;
    y=y_;
    z=z_;
}

mglVector3::mglVector3(const mglVector3& mVec)
{
    x=mVec.x;
    y=mVec.y;
    z=mVec.z;
}


mglVector3& mglVector3::operator=(const mglVector3 mVec)
{
        x=mVec.x;
        y=mVec.y;
        z=mVec.z;

        return *this;
}

mglVector3& mglVector3::operator=(const float array[3])
{
    x=array[0];
    y=array[1];
    z=array[2];

    return *this;
};

mglVector3& mglVector3::operator+=(const mglVector3& mVec)
{
    x+=mVec.x;
    y+=mVec.y;
    z+=mVec.z;

    return *this;
};

mglVector3& mglVector3::operator+=(const float array[3])
{
    x+=array[0];
    y+=array[1];
    z+=array[2];

    return *this;
}

mglVector3& mglVector3::operator-=(const mglVector3& mVec)
{
    x-=mVec.x;
    y-=mVec.y;
    z-=mVec.z;

    return *this;
}

mglVector3& mglVector3::operator-=(const float array[3])
{
    x-=array[0];
    y-=array[1];
    z-=array[2];

    return *this;
}

mglVector3& mglVector3::operator*=(float var)
{
    x*=var;
    y*=var;
    z*=var;

    return *this;
}


Now, this compiles fine as a library,but when I place library and file in the lib and include files of my compiler, and I try to use the vector, I get three errors;
.objs\main.o:main.cpp:(.text+0x224): undefined reference to `mglVector3::~mglVector3()'
.objs\main.o:main.cpp:(.text+0x24e): undefined reference to `mglVector3::~mglVector3()'
.objs\main.o:main.cpp:(.text$_ZN10mglVector3C1Efff[mglVector3::mglVector3(float, float, float)]+0x8): undefined reference to `vtable for mglVector3'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
If it helps, I'm using the latest stable version of Code::Blocks. I was just wondering what it is that I'm doing wrong?

Share this post


Link to post
Share on other sites
MaulingMonkey    1730
You sure the header hasn't changed since you last build that library? That class shouldn't even have a vtable without any polymorphic functions...

Also, just out of curiosity, why the inconsistency with passing by reference?

mglVector3& operator= (const mglVector3  mVec);
mglVector3& operator+=(const mglVector3& mVec);


(Also, you seem to be missing your include guard's closing #endif?)

Edit: You also seem to have some duplication going on here:

        //the form this vector+other vector
friend mglVector3 operator+(mglVector3 mVec1,const mglVector3& mVec2)
{
return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
}

//the form other vector+this vector
friend mglVector3 operator+(const mglVector3& mVec1,mglVector3 mVec2)
{
return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
}


There's no reason to have these seperate operators - try:

//the form vector+vector
friend mglVector3 operator+(const mglVector3& mVec1,const mglVector3& mVec2)
{
return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
}

Also, instead of implementing seperate operators for array additions, you should instead give mglVector3 a constructor that accepts arrays - then:

float array[3];
mglVector3 a;

mglVector3 b = a + array;


Will automatically create a temporary mglVector3 from a, and call the above version of operator+.

Share this post


Link to post
Share on other sites
webwraith    239
It did have a virtual destructor at one point, but I deleted it.

And the #endif is in the file, but there were some structures that come after, and it was only the mglVector3 class that I was having trouble with. Sorry for the confusion.

Thanks for the advice, though, I'll change that now.

Share this post


Link to post
Share on other sites
discman1028    212
Just as a side note, I would stay away from "virtual" and "protected" and the concepts involved with them until you get your vector class (and C++ syntax) down pat. Even "friends" might be somewhat misleading. In case you're just learning about polymorphism and inheritance, make them their own separate lessons. (Not too long ago, I took my own advice... 1 thing at a time.)

Don't know if that's the case here, but it helps me to introduce 1 new concept at a time, is all.

Share this post


Link to post
Share on other sites
webwraith    239
Nope, just changed it, still the same thing :P

Discman1028: Yup, that's what the last thread was all about. I got my class working too, the only trouble I'm having is when I try to use the compiled static library

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Affgoo
      About us:
      We are a team of 14 developers developing multiple mid scope games both are over halfway complete. We polish all of our games and focus on quality.


      We are a small team, everyone currently on the team and future teammates must be interested in game development as a whole and not just one role, being a small indie company it is very important that you can wear a few hats and not just one. Everyone on our team is a game dev.

      looking for:
      3d Artist (hand painting a huge plus)
      3d Animator
      entry level Software engineer with reasonable skills in c# / shaders. 

      ^ requirement for all positions: A true love of game development and to be very self motivated.
      We are a very active team, you must be too. 


      If interested or for more information add me on skype: nicholas.boucher4


      Atlas Sentry art style: (art complete)(code complete)
      http://www.slidedb.com/games/atlas-sentry

      Rat n Gat art style: In Devlopment

    • By EvaBalikova
      Main menu in Feudal Alloy. 
      twitter
    • By Jcyshadow97
      Hi guys,i m looking for someone that can work with me on a "top-down" multiplayer fps as 2d and 3d artist.I used photon server and i can take the part of programming.For now i made only the basic gameplay of the game that include shooting,switch weapon and and damage player.If someone can help me please contact me via e mail: 270514974@libero.it.
      I really appreciate your collaboration and hope you have a good day.....
      Thanks for you time to read the post
      At the bottom i attach some screenshot of the current game,i m sorry that i can't attach a video...



    • By Raptor42
      I'm looking to form a new game development team, mostly for training purposes.
      About me:
      I'm a student - Unity C# developer, who worked part-time in this industry for a couple of years already. I've been a lead developer in many "random collab groups" as well as a few companies. I specialize in creating 2D games for Android, but I'm looking forward to trying out new things - especially 3D development.
      Currently, I've got one Android game close to a release so I'd work for this team in my spare time. 
      About the project:
      I've been thinking about creating a simple tycoon-like simulation game for Android (and PC eventually), inspired by the Game Dev Story (initially released by Kairosoft in 1997) https://en.wikipedia.org/wiki/Game_Dev_Story 
      I haven't done much planning though, therefore I'm looking forward to hearing out your ideas.
      Right now, I've only created a test 3D scene using placeholder models and implemented a simple pathfinding system for me to play around with:
      https://i.imgur.com/xAd0l4o.png
      https://i.imgur.com/nHZerOT.png
      I'm looking to work with people who are:
      - willing to take a position of a: 3D modeller/2D artist/Designer
      - not necessarily very experienced, but eager to learn and improve their skills
      - active - check in at least once a day
      If you'd like to apply for a different position which I didn't list here, you are welcome to contact me as well.
      While this project is created mostly for learning purposes, if we ever get to release it and generate any revenue - you will recieve a certain percentage of it.
       
      To Apply:
      Send an email to rk.softwaredev@gmail.com
      Introduce yourself and attach an example of your work (if you have any)
    • By EvaBalikova
      Hello.

      We're a two-member team and I'd like to introduce you our game - Feudal Alloy. 
      It's a metroidvania-style action RPG with fishbowl-powered medieval robots.

      We've been working on the project for a few months. I'd be happy for any feedback.
      teaser
      homepage
      twitter
      facebook
       
      Our Steam page is public now: 
      steam link
       
       



  • Popular Now