Class function with string parameter

Hi, I'm trying to send a string to a class function.

tmpClass.h:
1
2
3
4
5
6
7
8
9
#include <string>

using namespace std;

class Tmp
{
public:
	void pointEasy(string bla);
};



tmpClass.cxx:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>

using namespace std;

class Tmp
{
	void pointEasy(string bla)
	{
		cout << "În pointEasy, bla:" << bla << "\n";
	}

};



tmpMain.cxx:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

#include "tmpClass.h"

using namespace std;

int main()
{
	Tmp tmp;
	string input;
	cin >> input;
	tmp.pointEasy(input);
	return 0;
}



When compiling, g++ spits this:
1
2
3
/tmp/ccYfAG3M.o: In function `main':
tmpMain.cxx:(.text+0x1be): undefined reference to `Tmp::pointEasy(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status



Why does the compiler stumble like this? If bla is of string type, and I pass a string to pointEasy, what am I doing wrong?
Your tmpClass.cxx file should be like this:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
#include "tmpClass.h"
using namespace std;

void Tmp::pointEasy(string bla)
{
	cout << "În pointEasy, bla:" << bla << "\n";
}

That's not how you define a member function of a class. Try this:

tmpClass.cxx:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
#include "tmpClass.h"

using namespace std;

void Tmp::pointEasy(string bla)
{
	cout << "În pointEasy, bla:" << bla << "\n";
}
Dammit, too slow :)
Argh.. sorry guys, it's been a while since I wrote c++ code... guess I need to skimp over a tutorial again.
Topic archived. No new replies allowed.