can't set inline member function

hello, please have a look at this:

Linija.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once
class Linija {
private:
	int x1, y1, x2, y2;
	void OdreziTocku(int Linija::* pok1, int Linija::* pok2, int v1, int v2, int p, int tip);
public:
	Linija();
	Linija(int px1, int px2, int py1, int py2);
	~Linija();
	void setX1(int x);
	void setX2(int x);
	void setY1(int y);
	void setY2(int y);
	int getX1() const;
	int getX2() const;
	int getY1() const;
	int getY2() const;
	void Odrezi(int px1, int py1, int px2, int py2);
};

Linija.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//...
/*other definititions*/
//...

//unresolved external simbol when calling this 
//functions from main function

inline int Linija::getX1() const {return x1;} 
inline int Linija::getX2() const {return x2;}
inline int Linija::getY1() const {return y1;}
inline int Linija::getY2() const {return y2;}
void Linija::setX1(int x) {x1 = x;}
void Linija::setX2(int x) {x2 = x;}
void Linija::setY1(int y) {y1 = y;}
void Linija::setY2(int y) {y2 = y;}


if I remove inline keyword it compiles just fine
but then meber function will not be inline and I dot want to put definiton into header file
same problem is if I put inline in header only or into both files
unresolved external simbol when function is called from main on some specific object like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Linija.h"
#include <iostream>
using std::cout;
Linija obj(10,20,30,49);

int main() {
        //those function cause exetrnal simbol errors
	obj.setX1(3);
	obj.setX2(4);
	obj.setY1(6);
	obj.setY2(9);
	obj.getX1(); 
	obj.Odrezi(40,4,-20,-10);
	return 0;
}


I'm using VS2010 C++ Expres
thanks for your help.
inline functions need to be in the header file, otherwise the won't be seen where they need to be inlined.
acording to my book, it says you can put definition outside the class and to make it inline then you need to put inline keyword, doesn't metter will you put inline before declaration or definition or both.
function will be inline.

so what are you saying I'll have to put functioin definition into header but ouside the class(which is in same header like this:

HEADER FILE "Linija.h"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
class Linija {
private:
	int x1, y1, x2, y2;
	void OdreziTocku(int Linija::* pok1, int Linija::* pok2, int v1, int v2, int p, int tip);
public:
	Linija();
	Linija(int px1, int px2, int py1, int py2);
	~Linija();
	void setX1(int x);
	void setX2(int x);
	void setY1(int y);
	void setY2(int y);
	int getX1() const;
	int getX2() const;
	int getY1() const;
	int getY2() const;
	void Odrezi(int px1, int py1, int px2, int py2);
};
inline int Linija::getX1() const {return x1;} 
inline int Linija::getX2() const {return x2;}
inline int Linija::getY1() const {return y1;}
inline int Linija::getY2() const {return y2;}


other functions into *cpp file which are not intende to be inline...
1
2
3
4
5
6
7
8
9
10
11
//...
/*other definititions*/
//...

//unresolved external simbol when calling this 
//functions from main function

void Linija::setX1(int x) {x1 = x;}
void Linija::setX2(int x) {x2 = x;}
void Linija::setY1(int y) {y1 = y;}
void Linija::setY2(int y) {y2 = y;}


Is that OK? or that has some disatvantages?
so what are you saying I'll have to put functioin definition into header but ouside the class(which is in same header like this:
Yes.

Is that OK? or that has some disatvantages?
That is ok, it's the way to do it. The compiler may still chose not to inline your function, but you can't really control that.
excelent, tnx for help mate!! :D
Topic archived. No new replies allowed.