Jump to content
  • Advertisement
Sign in to follow this  
Jouei

Dynamic multidimenstional Array or (Matrix ) linker error

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well i got this code from a tutorial and was from a good source but i get linker errors when i try and run the program it compiles fine it is to missing any libs for this code does not take any as far as i cam aware. and i get more linking errors when i try and split the code up into its own header file and its own source. i get mostly 2014 linking errors. just thought i would through this out there and see if anyone had any ideas. #include <vector> template<typename T> // See section on templates for more class Matrix { public: Matrix(unsigned nrows, unsigned ncols); // Throws a BadSize object if either size is zero class BadSize { }; // No need for any of The Big Three! // Access methods to get the (i,j) element: T& operator() (unsigned i, unsigned j); ← subscript operators often come in pairs const T& operator() (unsigned i, unsigned j) const; ← subscript operators often come in pairs // These throw a BoundsViolation object if i or j is too big class BoundsViolation { }; unsigned nrows() const; // #rows in this matrix unsigned ncols() const; // #columns in this matrix private: std::vector<std::vector<T> > data_; }; template<typename T> inline unsigned Matrix<T>::nrows() const { return data_.size(); } template<typename T> inline unsigned Matrix<T>::ncols() const { return data_[0].size(); } template<typename T> inline T& Matrix<T>::operator() (unsigned row, unsigned col) { if (row >= nrows() || col >= ncols()) throw BoundsViolation(); return data_[row][col]; } template<typename T> inline const T& Matrix<T>::operator() (unsigned row, unsigned col) const { if (row >= nrows() || col >= ncols()) throw BoundsViolation(); return data_[row][col]; } template<typename T> Matrix<T>::Matrix(unsigned nrows, unsigned ncols) : data_ (nrows) { if (nrows == 0 || ncols == 0) throw BadSize(); for (unsigned i = 0; i < nrows; ++i) data_.resize(ncols); } struct MAPDATA { int X; int Y; return 0; } int main() { Matrix <MAPDATA> TEST(20,20)' return 0; } fyi i could not remmber the code tags for gamedev nore could i track down an example so if someone could remind me please.

Share this post


Link to post
Share on other sites
Advertisement
Are your function definitions in the header file for the class?

Quote:
Original post by Jouei
fyi i could not remmber the code tags for gamedev nore could i track down an example so if someone could remind me please.


[source][/source] tags.

Share this post


Link to post
Share on other sites
No currently it is all a single source file but i still get a linking error about the line where i make a matrix of MAPDATA

if i have the code split into a header and source seperate form my main()

i get a total of 8 linking errors

sorry for the late reply my access to the internet lately is well limited at best

My compiler is vc++ 2008 just in case that is particularly important.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!