0
#ifndef CLASS_VEHICLE_
#define CLASS_VEHICLE_

#include "ns3/ptr.h"
#include "ns3/object.h"
#include "ns3/vector.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "Cluster.h"


namespace ns3
{
class Cluster;

/// define type DeviceTraceCallback
typedef Callback<void, Ptr<Vehicle>, std::string, Ptr<const Packet> > DeviceTraceCallback;  // Line where the error is
/// define type VehicleReceiveCallback.
typedef Callback<void, Ptr<Vehicle>, Ptr<const Packet>, Address> VehicleReceiveCallback;
/// define type PhyRxOkTraceCallback.
typedef Callback<void, Ptr<Vehicle>, std::string, Ptr<const Packet>, double, WifiMode, enum WifiPreamble> PhyRxOkTraceCallback; 
/// define type PhyRxErrorTraceCallback.
typedef Callback<void, Ptr<Vehicle>, std::string, Ptr<const Packet>, double> PhyRxErrorTraceCallback; 
/// define type PhyTxTraceCallback.
typedef Callback<void, Ptr<Vehicle>, std::string, Ptr<const Packet>, WifiMode, WifiPreamble, uint8_t> PhyTxTraceCallback; 
/// define type PhyStateTraceCallback.
typedef Callback<void, Ptr<Vehicle>, std::string, Time, Time, enum WifiPhy::State> PhyStateTraceCallback;

class Vehicle : public ns3::Object
{
  ... code section

 };
};
#endif

我正在研究 ns3,我必须实现一个代码,它可以让我对车辆网络进行一些模拟。我有几节课,但只有一节很烦人。事实上,当我编译时,我有这个特殊的错误:

“/src/vanet/model/Vehicle.h:45:错误:'DeviceTraceCallback'之前的声明符无效”

它带来了很多其他错误

“/src/vanet/model/Vehicle.h:212:错误:‘DeviceTraceCallback’没有命名类型”

或者

“../src/vanet/model/Vehicle.h:214:错误:‘DeviceTraceCallback’尚未声明”。

我真的不明白我做错了什么,所以如果有人可以帮助我,那就太好了!

4

1 回答 1

3

您还没有向我们展示错误所指的源代码行,但我假设它是这个:

typedef Callback<void, Ptr<Vehicle>, std::string, Ptr<const Packet> > DeviceTraceCallback; 

Have all the types and templates mentioned in that line been declared in one of the headers you've included? In particular:

  • You haven't directly included <string>. It's a good idea to do that, even if one of the other headers might include it indirectly.
  • You haven't declared the Vehicle type, defined later in this file. You'll need a declaration (class Vehicle; inside namespace ns {}) before you can use it in this declaration.
于 2012-08-09T14:49:07.450 回答