Archived

This topic is now archived and is closed to further replies.

OK, I must be tired (or my linker stoned)

This topic is 4944 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

in Point.hpp class Point { ... public: inline float getX() const ; } in Point.cpp inline float Point::getX() const { return mX; } main.obj : error LNK2001: unresolved external symbol "public: float __thiscall Point::getX(void)const " (?getX@Point@@QBEMXZ) Debug/Test.exe : fatal error LNK1120: 1 unresolved externals [edited by - xMcBaiNx on May 31, 2004 8:15:49 PM]

Share this post


Link to post
Share on other sites
Yes I did...

That''s pretty disturbing actually... calling pointInstance.anotherMethod() works quite fine, except for those three get Methods..

The only thing diffrente is this const thingy to say it can be called by const objects.

Share this post


Link to post
Share on other sites
You can't declare and define inline functions in separate files, you'll either have to declare and define it inside the class and you wont need to put "inline" or declare it in the class and define it outside the class but in the same file. I wouldn't use inline quantifier in a function declaration, quantifiy it on definitions like:


class Point {
float mX;
public:
float getX() const;
};

inline float getX() const {
return mX;
}


[edited by - snk_kid on May 31, 2004 8:31:51 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by spurious_interrupt
missing ; at the end of the class declaration?


All thought that is another mistake thats not the reason for that error, you need to define inline functions in the same translation unit

[edited by - snk_kid on May 31, 2004 8:36:19 PM]

Share this post


Link to post
Share on other sites
@snk_kid
Did not know that... tough it did not solve anything.

No the semicolons are all there I triple-checked..

That did not do the trick. Something else is wrong... It''s driving me insane because its probably a stupid mistake.

It is mind baffling... I have the EXACT SAME CODE in another class, and it works fine..

Anyway, I''ll probably figure it out and break my head on the desk when I find out

Share this post


Link to post
Share on other sites
That code compiles and runs fine but if you wont to use inline functions change things to:

Vector.hpp

#ifndef VECTOR_HPP
#define VECTOR_HPP

template<class T = float>
class Vector {
public:
Vector(const T = 0,
const T = 0,
const T = 0);
Vector(const Vector<T>&);
const Vector<T>& operator=(const Vector<T>&);

const T& x() const;
T& x();

const T& y() const;
T& y();

const T& z() const;
T& z();

const Vector<T>& x(const T);
const Vector<T>& y(const T);
const Vector<T>& z(const T);
private:
T _x, _y, _z;
};

template<class T>
inline Vector<T>::Vector(const T x,
const T y,
const T z): _x(x), _y(y), _z(z) {}


template<class T>
inline Vector<T>::Vector(const Vector<T>& v): _x(v._x),
_y(v._y),
_z(v._z) {}

template<class T>
inline const Vector<T>& Vector<T>::operator=(const Vector<T>& v) {
_x = v._x;
_y = v._y;
_z = v._z;
return *this;
}

template<class T>
inline const T& Vector<T>::x() const {
return _x;
}

template<class T>
inline T& Vector<T>::x() {
return _x;
}

template<class T>
inline const T& Vector<T>::y() const {
return _y;
}

template<class T>
inline T& Vector<T>::y() {
return _y;
}
template<class T>
inline const T& Vector<T>::z() const {
return _z;
}

template<class T>
inline T& Vector<T>::z() {
return _z;
}

template<class T>
inline const Vector<T>& Vector<T>::x(const T nx) {
_x = nx;
return *this;
}

template<class T>
inline const Vector<T>& Vector<T>::y(const T ny) {
_y = ny;
return *this;
}

template<class T>
inline const Vector<T>& Vector<T>::z(const T nz) {
_z = nz;
return *this;
}

#endif


main.cpp

#include "Vector.hpp"
#include <cstdlib>
#include <iostream>

int main() {
Vector<float> v(3.04f, 3.4f, 2.3f);

std::cout << v.x() << std::endl;

return EXIT_SUCCESS;
}


[edited by - snk_kid on May 31, 2004 9:20:47 PM]

Share this post


Link to post
Share on other sites
Well, getters and setters are fine but.. what about other more tense inline functions ? is there no way to hide the implementations (I guess it''d make sense if the compiler has to play with the code... it should know what it''s about..)

Share this post


Link to post
Share on other sites
Sorry no offical way of doing it, you can have look at .inl files here http://somewhere.fscked.org/inlsplit/ to achieve something simillar, i haven''t tried it thou.

Share this post


Link to post
Share on other sites