Cannot call function from main using custom static library
I cannot run the Display() function it gives me a
Unresolved external symbol_public:void _thiscall"
Severity Code Description Project File Line Suppression State
Error LNK1120 2 unresolved externals Project1 C:\Users\Ultimax\source\repos\Project1\Debug\Project1.exe 1
Error LNK2019 unresolved external symbol "public: void __thiscall Album::Display(void)" (?Display@Album@@QAEXXZ) referenced in function _main Project1 C:\Users\Ultimax\source\repos\Project1\Project1\Source.obj 1
Error LNK2001 unresolved external symbol "class Song * mysong" (?mysong@@3PAVSong@@A) Project1 C:\Users\Ultimax\source\repos\Project1\Project1\staticlib1.lib(Album.obj) 1
I am pulling my hair over this everything seems to be in order. It detects the libraries i made in the main cpp file.
Album Code
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
|
#include <string>
#include <iostream>
#include <fstream>
#include "album.h"
#include "artist.h"
#include "song.h"
#include "time.h"
using namespace std;
Song mysong[];
Album::Album() {
mysong[5];
Time theTime = Time(5,4);
for (int i = 0; i < 0; i++) {
mysong[i].setTime(theTime);
mysong[i].setTitle("theTitle");
}
}
void Album::setTitle(string q) {
albumtitle = q;
}
string Album::getTitle() {
return albumtitle;
}
//****************************************************
// Function: Read
//
// Purpose: Loads song data from a user specified file.
//
//
//****************************************************
void Read(string file) {
ifstream input(file, ios::out | ios::app);
}
//****************************************************
// Function: Write
//
// Purpose: Writes Data to a specified file.
//
//****************************************************
void Write(string filename) {
ofstream input(filename, ios::out | ios::app);
}
//****************************************************
// Function: Display
//
// Purpose: Loads to screen.
//
//****************************************************
void Display() {
//Display
for (int i = 0; i < 0; i++) {
cout << mysong[i].getTitle();
}
}
//Set & Get Functions
|
Main
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
|
//****************************************************
// File: source.cpp
//
// Purpose: to get user input and call functions.
//
//
// Compiler: Visual C++ 2013
#include <string>
#include <iostream>
#include <fstream>
#include "song.h"
#include "album.h"
int main() {
//Variables.
Album myalbum;
myalbum.Display();
system("pause");
}
|
Of course there are other libraries but the error seems to be only with album.Any help would be appreciated.
When defining a member function outside the class definition you need to write the class name before the function name.
1 2 3
|
void Album::Display() {
...
}
|
Last edited on
Thanks
Topic archived. No new replies allowed.