I'm (somewhat) new to C++ and I've been trying to get a program to work. It all compiles fine until I start to define a class constructor within the source file, even though I have declared it in the header file. I'm not sure if it's because I haven't defined all of my methods, because this is my second attempt at defining them (I'm literally rewriting them slowly to see if it helps).
The code in question is below (this is what is on the cpp file):
#include <cstdlib>
#include <iostream>
#include <string.h>
#include "StockItem.h"
Diode::Diode(char* componentT, char* code, int quantity, int price){
strcpy(componentType,componentT);
strcpy(stockCode,code);
stockQuantity = quantity;
unitPrice = price;
}
The output I receive is below:
cd 'G:\EDUCATION\University\Year 2\Year Courses\PROGRAMMING 2\Assignments\Assignment 2\COURSEWORK_100088688\StockProgram_C++'
C:\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/stockprogram_c__.exe
make[2]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockItem.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockItem.o.d" -o build/Debug/Cygwin-Windows/StockItem.o StockItem.cpp
StockItem.cpp: In member function 'void StockItem::setComponentType(char*)':
StockItem.cpp:27:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S1 = "resistor";
^
StockItem.cpp:28:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S2 = "capacitor";
^
StockItem.cpp:29:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S3 = "transistor";
^
StockItem.cpp:30:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S4 = "diode";
^
StockItem.cpp:31:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S5 = "ic";
^
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockProgram.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockProgram.o.d" -o build/Debug/Cygwin-Windows/StockProgram.o StockProgram.cpp
mkdir -p dist/Debug/Cygwin-Windows
g++ -o dist/Debug/Cygwin-Windows/stockprogram_c__ build/Debug/Cygwin-Windows/StockItem.o build/Debug/Cygwin-Windows/StockProgram.o
build/Debug/Cygwin-Windows/StockItem.o: In function `ZN9StockItemC2Ev':
/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++/StockItem.h:8: undefined reference to `vtable for StockItem'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0x8): undefined reference to `StockItem::getComponentInfo()'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0xc): undefined reference to `StockItem::setComponentInfo(char*)'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:63: recipe for target 'dist/Debug/Cygwin-Windows/stockprogram_c__.exe' failed
make[2]: *** [dist/Debug/Cygwin-Windows/stockprogram_c__.exe] Error 1
make[2]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-Debug.mk:60: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)
And just in case people need it, this is the class in question:
class Diode : public StockItem {
public:
Diode(char* componentT, char* code, int quantity, int price);
Diode(const Diode &D);
Diode& operator=(const Diode& D);
~Diode();
};
My question is why is this effecting the compilation? Any feedback (regardless of relevance) is greatly appreciated, thank you.