c++ - "Declaration of xxx outside of class is not definition" error -


this error:

error: declaration of 'datastream::datastream()' outside of class not definition [ fpermissive]| ||=== build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===| 

this main.cpp file:

#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(); } 

datastream::datastream(); 

is declaration of constructor class datastream, must declared within class not outside.

class datastream {     public:         datastream(); }; 

further, can define constructor inline inside class or outside, like

datastream::datastream() {} 

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 -