Multiple cpp files

I've read through the articles and previous forum questions on the subject, but couldn't find what I wanted, so...

I've been creating a program for a while now using just one .h and one .cpp, but it's starting to get big and messy with all the different classes I'm using, so I'd like to cut the class definitions into separate .cpp files. I tried doing that for just one class and immediately got "unresolved external" errors regarding the class I'd just moved to a new .cpp. Here's the code (I've removed the actual definitions to save space).

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//Qt.h
#ifndef QT_H
	#define QT_H

#include <iostream>
#include <cstdlib>
#include <SFML/Graphics.hpp>
#include <QtCore/QFile>
#include <QtCore/QString>
#include <QtCore/QTextStream>
#include <QtGui/QShortcut>
#include <QtCore/QTimer>
#include <QtGui/QFrame>
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>

class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
	QTimer Timer;
	bool Initialized;
	virtual void OnInit();
	virtual void OnUpdate();
	virtual QPaintEngine* paintEngine() const;
	virtual void showEvent(QShowEvent*);
	virtual void paintEvent(QPaintEvent*);
public:
	QSFMLCanvas(QWidget* parent, const QPoint& pos, const QSize& size, unsigned int frametime=0);
	virtual ~QSFMLCanvas();
	QSFMLCanvas();
};
class MyCanvas : public QSFMLCanvas
{
public :

    MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size);
	MyCanvas();
private :
    void OnInit();
    void OnUpdate();
};

struct Object
{
	sf::Shape shape;
};
struct Line : public Object
{
	bool f(float depth); 
};
struct Point : public Object
{
	sf::Vector2f coord; 
	int n;
	Point();
	Point(float x,float y);
};
class Base : public QWidget
{
	Q_OBJECT
private:
	QFile pl; 
	QTextStream _pl;
	QFrame Frame;
	Point MouseCoords; 
	sf::View CurrentView; 
	sf::View GlobalView;
	std::vector<Line> faults;   
	std::vector<Line> horizons; 
	std::vector<Point> points; 
	void ChangeView_Wheel(int Delta); 
	void DesignFault();
	void DesignHorizon(); 
	void DesignLine(Point pt1, Point pt2); 
	Line* NewLine(); 
	void SaveFaultPoints(int elevation,int n);
	void SaveFaultSegments();
private slots:
		void ChangeView_Key(); 
public:
	MyCanvas* App;
	Base();
	void Show();
	void DrawAll();
	~Base();
public slots:
	void OpenFile(QString str); 
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Qt.cpp
#include "QT.h"

QFile _stderr;
float t; //global thickness
Point::Point() {/*...*/}
Base::Base() {/*...*/}
void Base::ChangeView_Key() {/*...*/}
void Base::DesignFault() {/*...*/}
void Base::DesignLine(Point pt1, Point pt2) {/*...*/}
Line* Base::NewLine() {/*...*/}
void Base::OpenFile(QString str) {/*...*/}
void Base::SaveFaultPoints(int elevation,int num) {/*...*/}
void Base::SaveFaultSegments() {/*...*/}
void Base::Show() {/*...*/}
Base::~Base() {/*...*/}
MyCanvas::MyCanvas() {/*...*/}
MyCanvas::MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) {/*...*/}
void MyCanvas::OnInit() {/*...*/}
void MyCanvas::OnUpdate() {/*...*/}
int main(int argc, char *argv[]) {/*...*/}


1
2
3
4
5
6
7
8
9
10
11
//QSFMLCanvas.cpp
#include "QT.h"

QSFMLCanvas::QSFMLCanvas() {/*...*/}
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) {/*...*/}
QSFMLCanvas::~QSFMLCanvas() {/*...*/}
void QSFMLCanvas::OnInit() {/*...*/}
void QSFMLCanvas::OnUpdate() {/*...*/}
QPaintEngine* QSFMLCanvas::paintEngine() const {/*...*/}
void QSFMLCanvas::paintEvent(QPaintEvent*) {/*...*/}
void QSFMLCanvas::showEvent(QShowEvent*) {/*...*/}


However, I now get "unresolved external" errors regarding all the QSFMLCanvas functions called from Qt.cpp.
Be sure that you are compiling and linking all of the newly created .cpp files into your project.
Yeah, that was it. VC++ said it was included in the project, but since I'm using Qt and its qmake compiler, I forgot I had to add QSFMLCanvas.cpp to the .pro file. Did that and it worked like a charm.
Topic archived. No new replies allowed.