Here are the two header files.Child and parent.Can anyone explain why this error occures?
Thanks in advance
SampleApplication.h:
#ifndef SAMPLEAPPLICATION_H_
#define SAMPLEAPPLICATION_H_
#include "ns3/CcnModule.h"
#include "ns3/CCN_Name.h"
#include <string>
class CcnModule;
class SampleApplication : public ns3::Application
{
public:
ns3::Ptr<CcnModule> ccnm;
static ns3::TypeId GetTypeId(void);
virtual ns3::TypeId GetInstanceTypeId (void) const;
SampleApplication();
SampleApplication(ns3::Ptr<CcnModule> ccnm);
virtual ~SampleApplication();
char* data;
int length;
ns3::Ptr<CCN_Name> dataName;
void SendInterest(ns3::Ptr<CCN_Name> n);
void SendData(ns3::Ptr<CCN_Name> data, char* buff, int bufflen);
virtual void InterestReceived(ns3::Ptr<CCN_Name> ccnn);
virtual void DataArrived(ns3::Ptr<CCN_Name> data, char* buff, int bufflen);
void AnnounceName(ns3::Ptr<CCN_Name> n);
virtual void DoDispose();
virtual void DoInitialize();
};
#endif
Receiver.h:
#ifndef RECEIVER_H_
#define RECEIVER_H_
#include "ns3/CcnModule.h"
#include "ns3/CCN_Name.h"
#include <string>
#include <vector>
#include "ns3/SampleApplication.h"
class CcnModule;
//class SampleApplication;
class Receiver : SampleApplication
{
public:
static ns3::TypeId GetTypeId(void);
virtual ns3::TypeId GetInstanceTypeId (void) const;
Receiver(ns3::Ptr<CcnModule> ccnm);
virtual ~Receiver();
void SendInterest(ns3::Ptr<CCN_Name> n);
virtual void DataArrived(ns3::Ptr<CCN_Name> data, char* buff, int bufflen);
};
#endif
I am not familiar with library you are using but I am guessing it is the NS-3 Discrete Event Network Simulator and from a cursory glance at the API I would expect to see the include
#include "ns3/application.h"
In your SampleApplication.h file.
It may well be that it is already pulled in by some of those other includes in your implementation but at first glance it appears to be missing.
Related
I'm still a noobie in c++ so I am not to skilled in debugging yet. Just trying to figure out how to fix this compilation error.
CruiseShip.cpp:11: error: expected ā)ā before ānā
CruiseShip.cpp
#include "CruiseShip.h"
#include "Ship.h"
#include <iostream>
using namespace std;
Ship s;
int passengers;
CruiseShip(string n, string y, int p) : Ship(n,y)
{
passengers=p;
}
void print()
{
cout<<"Name: "<<s.getName()<<"\nMaximum passengers:"<<passengers<<endl;
cout<<"-------------------------"<<endl;
}
CruiseShip.h
#ifndef CRUISESHIP_H
#define CRUISESHIP_H
#include "Ship.h"
#include <string>
using namespace std;
//class Ship;
class CruiseShip:public Ship{
private:
int passengers;
Ship::Ship s;
public:
CruiseShip(string, string, int);
virtual void print();
};
#endif
Ship.h
#ifndef SHIP_H
#define SHIP_H
#include <string>
using namespace std;
class Ship{
private:
string name;
string built;
public:
Ship();
Ship(string, string);
string getName();
string getBuilt();
virtual void print();
};
#endif
You have 3 errors:
1 and 2. You don't declare print and CruiseShip (The constructor) as part of the class CruiseShip when you define them. You need to:
CruiseShip::CruiseShip(string n, string y, int p) : Ship(n,y) {
virtual void CruiseShip::print() {
3, you dont have a namespace Ship so this is unnecessary:
Ship::Ship s; // This only needs to be Ship s <- NameSpace::ObjectType nameOfObject;
After this it will compile http://ideone.com/wJ6mPO. It will not link however, because you have undefined references to all of the functions you have yet to define.
Why this in Client.cpp file I'm getting error C2065:'TunnelContainer': undefined identifier?
Client.cpp code:
#include "stdafx.h"
#include "GClientLib.h"
using namespace GClientLib;
int _tmain(int argc, _TCHAR* argv[])
{
SettingsReader^ settings = gcnew SettingsReader();
SocketToObjectContainer^ STOContainer = gcnew SocketToObjectContainer();
TunnelContainer^ tunnels = gcnew TunnelContainer();
timeval time;
time.tv_sec = 0;
time.tv_usec = 300000;
....
GClientLib.h code fragment:
#include "Structures.h"
#include "Globals.h"
#include "SettingsReader.h"
#include "SocketToObjectContainer.h"
#include "SocketToSocketContainer.h"
#include "TunnelContainer.h"
Updated. SocketToSocketContainer.h
#ifndef SocketToSocketContainer_H
#define SocketToSocketContainer_H
#include <cliext/utility>
#include <cliext/list>
#include <cliext/algorithm>
namespace GClientLib {
ref class SocketToSocketContainer {
private:
cliext::list<cliext::pair<int, int>> sarasas;
public:
SocketToSocketContainer(void);
void Add(int, int);
int Find(int);
void Delete(int);
};
};
#endif
GclientLib is lib project, used in Client application. Build on Visual Studio 2013 C++/CLI enabled
TunnelContainer.h code:
#ifndef GClientLib_H
#define GClientLib_H
#include <cliext/utility>
#include <cliext/list>
#include <cliext/algorithm>
namespace GClientLib {
enum TunnelStatus
{
JUNGIASI = 1, //Uzmezgamas rysys tarp klientu
LAUKIA_PROGRAMOS = 2, // Laukia kol prisijungs norima kliento porgramine iranga
KOMUNIKACIJA = 3 // Tuneliu vyksta komunikacija
};
ref struct Tunnel
{
int tag; //Tunelio zyme
int dport; //Prievadas, prie kurio jungesi
int clientid; //Kliento ID su kuriuo sujungta
int sport; //Vietinis prievadas
int serverSocket; //Socketas, prie kuris priima duomenu srauta
int status; // Sujungimo statusas (Jungiasi, prisjungta, laukia jungties)
};
ref class TunnelContainer {
private:
// Tuneliu sarasas
cliext::list<cliext::pair<int, Tunnel^>> sarasas;
public:
// Konstruktorius
TunnelContainer();
// Pridedamas naujas tunelis. PERRASO statusa i JUNGIAMASI
Tunnel^ Add(Tunnel^ tunelis);
// Pridedamas naujas tunelis. Statusa nustato i JUNGIAMASI
Tunnel^ Add(int tag, int dport, int clientid, int sport, int serverSocket);
// Tunelio paieska pagal tag
Tunnel^ Find(int tag);
// Salina tuneli pagal tag
Tunnel^ Remove(int tag);
// Keicia tunelio statusa
void ChangeStatus(int tag, TunnelStatus status);
};
};
#endif
UPDATE
After moving TunnelContainer.h into first position getting this error in ToServerSocket.h file:
Error 1 error C2143: syntax error : missing ';' before '^' line 16
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int line 16
ToServerSocket.h code:
#ifndef ToServerSocket_H
#define ToServerSocket_H
#include <iostream>
#include "gNetSocket.h"
#include "ServerSocket.h"
#include "OutboundSocket.h"
namespace GClientLib {
ref class ToServerSocket : public gNetSocket {
private:
char *commandBuffer;
line 16 --->TagGenerator^ tag;
SocketToObjectContainer^ STOC;
SettingsReader^ settings;
public:
ToServerSocket(string ip, string port, fd_set* skaitomiSocket, fd_set* rasomiSocket, fd_set* klaidingiSocket, SocketToObjectContainer^ STOC, SettingsReader^ settings);
virtual int Send(char* data, int lenght) override;
virtual void Recive(SocketToObjectContainer^ container) override;
virtual void Connect() override;
virtual void Reconnect() override;
void CommandList(int page);
void CommandListAck(int rRecv);
void CommandHello();
void CommandHelp();
void CommandInitConnect(int id, int port, SocketToObjectContainer^ container);
void CommandConnect(SocketToObjectContainer^ container);
void CommandClear();
void CommandBeginRead(SocketToObjectContainer^ container);
void CommandClientConnectAck(SocketToObjectContainer^ container);
void CommandInitConnectAck();
void CommandJsonList(int page, SOCKET socket);
void CommandJsonListAck(int rRecv, SocketToObjectContainer^ container);
void CommandJsonInitConnect(int id, int port, SOCKET socket);
void CommandJSONConnect(SocketToObjectContainer^ container);
void CommandJsonInitConnectAck();
int GenerateTag();
};
};
#endif
you probably have a syntax error or missing ; or missing closing " in the include before that, "SocketToSocketContainer.h".
#include is a precompiler statement, all it does is include the content of the given file into the main file; it is your task to make sure that the result is a valid code. So if one include has an incomplete statement, the content of the second include continues that statement.
Edit: It could be even further up in the list - any open or incorrect #IFDEF in any include could remove the whole rest
I have found my mistake. GClientLib_H was already defined.
#ifndef GClientLib_H
#define GClientLib_H
Changed to
#ifndef TunnelContainer_H
#define TunnelContainer_H
Now everything is working. Thank you for quick responses
I've looked around, and I can't quite figure out where I'm going wrong, as I seem to be following the correct convention when using interfaces, but perhaps I'm overlooking something. The exact error I'm getting is:
undefined reference to `vtable for Icommand'
I've only just begun to seperate my classes and class declarations into separate header files, so perhaps I'm missing a preprocessor directive somewhere.
main.cpp:
#include <iostream>
#include <string>
#include <cstdlib>
#include "Icommand.h"
#include "Command.h"
using namespace std;
void pause();
int main(){
Icommand *run = new Command("TEST");
cout << run->getCommand() << endl;
delete run;
pause();
}
void pause(){
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
cin.get();
}
Icommand.h:
#ifndef ICOMMAND_H
#define ICOMMAND_H
#include <string>
#include <vector>
class Icommand
{
private:
public:
Icommand(){}
virtual ~Icommand(){}
virtual bool run(std::string object1) = 0;
virtual bool run(std::string object1, std::string object2) = 0;
virtual std::string getCommand() const;
};
#endif // ICOMMAND_H
Command.h:
#ifndef COMMAND_H
#define COMMAND_H
#include <string>
#include <vector>
#include "Icommand.h"
class Command : public Icommand {
private:
std::string command;
std::vector<std::string> synonymns;
Command(); // private so class much be instantiated with a command
public:
Command(std::string command) : command(command){}
~Command(){}
bool run(std::string object1);
bool run(std::string object1, std::string object2);
std::string getCommand() const;
};
#endif // COMMAND_H
Command.cpp:
#include <string>
#include <vector>
#include "Command.h"
bool Command::run(std::string object1){
return false;
}
bool Command::run(std::string object1, std::string object2){
return false;
}
std::string Command::getCommand() const {return command;}
In Icommand.h, replace
virtual std::string getCommand() const;
with
virtual std::string getCommand() const = 0;
to make it pure virtual. Then the compiler can generate a vtable for Icommand. Alternatively, implement Icommand::getCommand.
I'm pretty sure I've included the qanda class, but when I try to declare a vector that contains it or a class of that type I get an error saying that qanda is undefined. Any idea what the problem might be?
bot_manager_item.h
#pragma once
#include "../bot_packet/bot_packet.h"
#include <vector>
class bot_manager_item;
#include "qanda.h"
#include "bot_manager.h"
class bot_manager_item
{
public:
bot_manager_item(bot_manager* mngr, const char* name, const char* work_dir);
~bot_manager_item();
bool startup();
void cleanup();
void on_push_event(bot_exchange_format f);
bool disable;
private:
void apply_changes();
bot_manager *_mngr;
std::string _name;
std::string _work_dir;
std::string _message;
std::string _message_copy;
std::vector<qanda> games;
qanda test;
char _config_full_path[2600];
};
qanda.h
#ifndef Q_AND_A
#define Q_AND_A
#include "users.h"
#include "..\bot_packet\bot_packet.h"
#include "bot_manager.h"
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <fstream>
class qanda
{
public:
qanda(bot_manager * manager, std::string name, std::string directory);
~qanda(){};
void room_message(std::string username, std::string user_message);
void timer_tick();
private:
// data members
std::string question;
std::string answer;
std::string directory;
std::string command_prefix;
std::string name;
Users users;
std::map <std::string, std::string> questions_and_answers;
int time_per_question; // seconds
int time_between_questions; // seconds
int timer; // milliseconds
bool is_delayed;
bool is_playing;
bot_manager * manager;
// functions
void new_question();
void send_message(std::string msg);
void announce_question();
void load_questions();
};
#endif
Solved: I ended up refactoring the code in such a way as to avoid the use of bot_manager within the qanda class.
I suspect a circular #include problem. Is it possible qanda.h indirectly includes bot_manager_item.h?
It looks like you may be able to reduce header dependencies by using a forward declaration
class bot_manager;
instead of #include "bot_manager.h" in one or both of your posted header files.
This might be an easy question, but I cannot figure out why the compiler it's giving me this error. I have two classes. Agent and Environment. WHen I try to add an object of type Agent in my Environment class I get Agent does not name to a type error. I am including Agent.h in my Environment.h class
#ifndef AGENT_H_INCLUDED
#define AGENT_H_INCLUDED
#include <vector>
#include <iostream>
#include "Environment.h"
using namespace std;
class Agent{
public:
Agent(bool s);
vector<int> getPercept();
void setPercept(vector<int> p);
void goForward();
void turnRight();
void turnLeft();
void clean();
void paint();
void refuel();
bool needsRefuel();
void turnOn();
void turnOff();
bool isActive();
void move();
int getCurX();
int getCurY();
char getCurDir();
void setCurrentPosition(int x, int y, char d);
private:
vector<int> percept;
int actions;
int performance;
char direction;
bool isOn;
int curX;
int curY;
char curDir;
};
#endif // AGENT_H_INCLUDED
/*************************/
#ifndef ENVIRONMENT_H_INCLUDED
#define ENVIRONMENT_H_INCLUDED
#include <vector>
#include <iostream>
#include "Agent.h"
using namespace std;
class Environment{
public:
Environment(vector<vector<char> > roomData);
Environment(vector<vector<char> > roomData, vector<int> status);
void setRoomData(vector<vector<char> > roomData);
bool isSimulationComplete();
void isAgentHome();
vector<int> sendLocationStatus();
void printEnvironment();
void setAgentHome(int x, int y);
vector<int> getAgentPercept();
void setAgentPercept(vector<int> status);
void setAgentPosition(int x, int y, char p);
vector<int> sendAgentPercept();
void calculateAgentPercept();
private:
vector<vector<char> > room;
vector<int> agentPercept;
bool simulationComplete;
int agentHomeX;
int agentHomeY;
int agentX;
int agentY;
char agentDir;
Agent agent; ////ERROR IS HERE
};
#endif // ENVIRONMENT_H_INCLUDED
Your agent.h includes environment.h. The agent.h file is parsed in order from top to bottom, so when environment.h is parsed, the compiler doesn't know what an Agent is. There appears to be no reason to incude environment.h in agent.h.
Apart from what the comments already said, you can't have two header files include each other. There is no reason for Agent.h to include Environment.h, so if a .cpp file includes Agent.h first, it'll fail (since it will first go through Environment.h, which requires Agent).
IF you have a situation where two header files depend on each other's definitions, use forward declarations where you can, or split your header files up into more header files.