Undefined reference to a class

Hi! I can't figure out what's wrong with this very stupid code: when I try to compile it, that's what I get:

jacopo@jacopo-laptop:~/Documenti/C++ Prove$ g++ DistribCarte.cpp -o DistribCarte/tmp/ccl0QGgB.o: In function `main':
DistribCarte.cpp:(.text+0x15): undefined reference to `DeckOfCards::DeckOfCards()'
DistribCarte.cpp:(.text+0x21): undefined reference to `DeckOfCards::shuffle()'
DistribCarte.cpp:(.text+0x32): undefined reference to `DeckOfCards::~DeckOfCards()'
DistribCarte.cpp:(.text+0x47): undefined reference to `DeckOfCards::~DeckOfCards()'
collect2: ld returned 1 exit status

Could someone help me? Thanks!!!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//******Header File: DeckOfCards.h************
#ifndef DeckOfCards_H
#define DeckOfCards_H 

class DeckOfCards
{
	public:
		DeckOfCards();
		~DeckOfCards();
		void shuffle();
		
	
	private:
		int deck[4][13];
		
};
#endif
//************************
//********DeckOfCards.cpp*************
#include <iostream>

using namespace std;

#include "DeckOfCards.h"

DeckOfCards::DeckOfCards()
{
	for(int row= 0; row <= 3; row++)
	{	
		for(int column = 0; column<= 12; column++)
		{
			deck[row][column] = 0;
		}
	}
	
}

DeckOfCards::~DeckOfCards(){}

void DeckOfCards::shuffle()
{
	cout <<"Hello!"<<endl;
}
//*************************************


//********DistribCarte.cpp***********
#include <iostream>
using namespace std;
#include "DeckOfCards.h"

int main()
{
	DeckOfCards deckOfCards;
	
	deckOfCards.shuffle();

	return 0;
}

g++ DistribCarte.cpp -o DistribCarte/tmp/ccl0QGgB.o

Add the -c option (compile, but do lot link):

g++ -std=c++11 -Wall -Wextra -pedantic-errors -c DistribCarte.cpp -o DistribCarte/tmp/ccl0QGgB.o
Thanks JLBorges! However, I get:

jacopo@jacopo-laptop:~/Documenti/C++ Prove$ g++ -std=c++11 -Wall -Wextra -pedantic-errors -c DistribCarte.cpp -o DistribCarte
cc1plus: error: unrecognized command line option ‘-std=c++11’

or, if I leave -std=c++11 out:

jacopo@jacopo-laptop:~/Documenti/C++ Prove$ g++ -Wall -Wextra -pedantic-errors -c DistribCarte.cpp -o DistribCarte
jacopo@jacopo-laptop:~/Documenti/C++ Prove$ ./DistribCartebash: ./DistribCarte: Permission denied

Did I understand properly?
An object file is not an executable as it is not linked yet, that is why is has the traditional extension .o

What does g++ --version say? You may want to update since it doesn't recognize C++11 - the latest version is 4.8.2.
Thanks L B!
Yes, actually it is an old one, 4.6.3, better to update. However, as far as I understand, it should work anyway, shouldn't it?
Add DeckOfCards.cpp after DistribCarte.cpp in the command line.

About ./DistribCarte, add permission to execute.
Yes!!!!!

Many many thanks EssGeEich, that was it! These stupid beginners ;)
Topic archived. No new replies allowed.