Derived classes from DLL

I've created a base DLL for all my future DLL's, a way of getting version numbers and such and that compiles fine, but I can't add it into a class for a new DLL.
All the headers do have an appropriate cpp to define the function declarations (and they compile fine).

All for the base DLL I have:
LibVer.h
Version.cpp
Function.cpp

LibVer.h
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
#pragma once
#include <vector>

#define DLLEXPORT 1
#define DLLIMPORT 2
#define DLL DLLIMPORT

#if DLL == DLLEXPORT
#undef DLL
#define DLL __declspec(dllexport)
#else
#undef DLL
#define DLL __declspec(dllimport)
#pragma comment(lib, "Debug/LibVer.lib")
#endif

namespace LibVer{
	class DLL Function{
	protected:
		char* type;
		char* name;
		char** args;
	public:
		Function(char type[], char name[], char* args[]);
		~Function();

		bool operator==(Function arg);
		bool operator==(Function* arg);

		char* getReturnType();
		char* getName();
		char** getArgTypes();
	};
	class DLL Version{
	protected:
		static const int Major = 1;
		static const int Minor = 0;
		static const int Patch = 0;
		std::vector<Function> functions;
	public:
		bool hasFunction(Function minVerSpecs);
		void addFunction(Function funcSpecs);
		void addFunction(Function* function);
		bool remFunction(Function funcSpecs);
		bool remFunction(Function* function);

		int getMajorVersion();
		int getMinorVersion();
		int getPatchVersion();
	};
}


Inside the derived header...
Maths_DLL.h
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
#pragma once
#include <cmath>
#include "../../LibVer/LibVer DLL/LibVer.h" //Dir of "LibVir.h", "LibVir.dll" and "LibVer.lib"

#ifndef PI
#define PI 3.141591653589793
#endif
#define DEG_PER_RAD 57.29577951308232
#define RAD_PER_DEG 0.017353292519943

namespace ExMaths{//Extra Maths Library
	class __declspec(dllexport) ExMaths: protected LibVer::Version{
	public:
		ExMaths();
		template<typename T> T* orderSL(int number, T var[]);
		template<typename T> T* orderLS(int number, T var[]);
		template<typename T> T* orderReverse(int number, T var[]);
		template<typename T> void swap(T& var1, T& var2);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		double toDegrees(double radians);		//Returns degree conversion of given radians
		double toRadians(double degrees);		//Returns radian conversion of given degrees
		double toBearing(double degrees);		//Returns clockwise rotation in degree from Y+
		double fromBearing(double degrees);	//Returns elevation rotation in degree from X+
		double rectifyAngle(double degrees, bool ABS = false);	//Limits the degrees of an angle to (-180|180)false, (0|360)true
		
		double polR(double x, double y);				//Returns the length from (0, 0) to (x, y)
		double polT(double x, double y);				//Returns the angle of elevation from (0, 0) to (x, y)
		double recX(double radius, double theta);		//Returns the X coordinate from a polar point of (radius, angle of elevation)
		double recY(double radius, double theta);		//Returns the Y coordinate from a polar point of (radius, angle of elevation)

		double pythag(int num, double roots[]);		//Calculates pythagorous theorum for array of lengths given
		double average(int num, double sums[]);		//Calculates the mean average for array of numbers given
	};
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
 
#pragma once
#include <cmath>

#ifndef PI
#define PI 3.141591653589793
#endif
#define DEG_PER_RAD 57.29577951308232
#define RAD_PER_DEG 0.017353292519943

namespace ExMaths{//Extra Maths Library
	class ExMaths: public Version{//Error: not a class or struct name 

Two issues:
1) You're not including version.h.
2) The reference needs to be Version::Version because of the namespace, or specify using namespace Version
Using...
1
2
3
4
5
6
7
8
9
#include "../../Version/Version/Version.h" //Correct location of Version.j

//definitions...

namespace ExMathc{
    class ExMaths: public Version::Version{//Error: invalid base class
    //...
    }
}


Also I thought that the point of a DLL was that things didn't need to be "included" as that would add them to the full source file (or full .exe or whatever).
I thought the idea was that DLL's where used so updates can be made without recompiling the entire source file, but if it's included that basically writes all the information in place of the include doesn't it? So everything which includes it needs to be recompiled?
Last edited on
Don't export methods of a class, export the whole class.
Didn't work... 100+ errors, will update code as soon as I can (and will notify here)
Also I thought that the point of a DLL was that things didn't need to be "included" as that would add them to the full source file (or full .exe or whatever).

A header file tells the compiler how to call the functions declared in the header. A header file shouldn't contain executable code. Without a header file for a DLL, when your code is compiled, the compiler will generate errors because it doesn't know how to call functions in the DLL. In this respect, a DLL is no different from any other separately compiled library. The only difference being that the external references are resolved at run time rather than at link time.


I thought the idea was that DLL's where used so updates can be made without recompiling the entire source file

That's the idea as long as the header doesn't change, or only changes in a compatible way. For example, adding a function to a class in a header won't break any of the other declarations in the header.


but if it's included that basically writes all the information in place of the include doesn't it?

No. Header files contain declarations of functions, not implementations of functions.
Implementations go in .cpp files.




Hey I've updated the topmost post and code...

I only get one error saying
cannot open file 'LibVer.lib'

And only one warning saying
'LibVer::Version::functions' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'LibVer::Version'
Last edited on
Topic archived. No new replies allowed.