c++ - Trying to compile and receiving the following errors, undefined references to certain classes. -


these errors have occured when trying compile file main.cpp:

 c:\users\student\desktop\c++ solution framework (1)\assignmentsolution\assignmentsolution\main.o:main.cpp|| undefined reference   `msgpacket::msgpacket(int, int, int, int, std::string)'|  c:\users\student\desktop\c++ solution framework (1)\assignment solution\assignmentsolution\main.o:main.cpp|| undefined reference `datastream::datastream()'|  ||=== build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===| 

this main.cpp file itself:

#include <iostream> #include <iomanip> #include "datastream.h" #include "msgpacket.h"   using namespace std;  datastream * packet = new datastream(); datastream::datastream();    int main() {  int source; int destination; int type; int port; int input; std::string data;  cout << "my assignment" << endl;;   msgpacket * packet = new msgpacket(source,destination,type,port,data); } 

this msgpacket.h

#ifndef msgpacket_h #define msgpacket_h  #include <string> #include "packetaddress.h"  using namespace std;  class msgpacket : public packetaddress { public:     msgpacket();     msgpacket (const msgpacket & rhs);     msgpacket(string datain);     msgpacket(int source, int destination, int port, int type, std::string data);     msgpacket(int ,char data);     string tostring();     string getdata() const {return _data;};     void setdata(string indata) {_data = indata;};     string dataoutput();     virtual ~msgpacket();     virtual msgpacket * clone() { return new msgpacket(*this); } protected:     string _data; };  #endif // msgpacket_h 

and msgpacket.cpp

#include <stdio.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <string> #include <iomanip> #include "msgpacket.h"   using namespace std;  msgpacket::msgpacket(): packetaddress(0,0) {  }  msgpacket::msgpacket (const msgpacket & rhs): packetaddress(rhs), _data(rhs.getdata()) {  }  msgpacket::msgpacket(string datain): packetaddress(0,0){ string temp; temp = datain.substr (0,4); _source = atoi(temp.c_str()); temp = datain.substr (5,4); _dest = atoi(temp.c_str()); temp = datain.substr (10,4); _type = atoi(temp.c_str()); temp = datain.substr (15,4); _port = atoi(temp.c_str()); _data = datain.substr (20,datain.length()); #ifdef debug cout << "create packet: " << this->tostring() << endl; #endif }  msgpacket::msgpacket(int source, int destination): packetaddress(source,destination) {   }   msgpacket::msgpacket(int source, int destination, int port): packetaddress(source,destination) {  _port = port; }   msgpacket::msgpacket(int source, int destination, int type, int port, std::string       data):  packetaddress(source, destination) { _source = source; _dest = destination; _type = type; _data = data; _port = port; }  string msgpacket::dataoutput() { stringstream output;//create stringstream output << setw(4) << setfill('0') << _source << ":" <<  setw(4) << setfill('0') <<  _dest << ":" << setw(4) << setfill('0') << _type << ":" << setw(4) << setfill('0') << _port     << ":" << _data;  return output.str(); }   string msgpacket::tostring() { stringstream output;//create stringstream output << "[" << showbase << hex <<  << "] s:[" << _source << "] d:[" << _dest << "] p:[" << _type << "] t:[" << _port << "]" << " data[" << _data << "]"; return output.str(); } 

undefined reference to means you're trying refer cannot linked. linking 2 cpp files together?


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -