erreur: expected constructor, destructor, or type conversion before ‘(’ token

1,164 views
Skip to first unread message

Belkneni Maroua

unread,
Mar 7, 2014, 7:06:34 AM3/7/14
to ns-3-...@googlegroups.com
hi, i want to inherit the functionalities from Adhoc-wifi-mac 
i have myadhoc-wifi-mac.h                                                and                                                                   myadhoc-wifi-mac.cc

#ifndef MYADHOC_WIFI_MAC_H                                                                                                                #include "myadhoc-wifi-mac.h"                                                                                                                                                                                                                                         
#define MYADHOC_WIFI_MAC_H                                                                                                               NS_LOG_COMPONENT_DEFINE ("myAdhocWifiMac");
#include "ns3/regular-wifi-mac.h"                                                                                                                  namespace ns3 {
#include "ns3/adhoc-wifi-mac.h"                                                                                                                   NS_OBJECT_ENSURE_REGISTERED (myAdhocWifiMac);
                                                                                                                                                                  TypeId
namespace ns3 {                                                                                                                                          myAdhocWifiMac::GetTypeId (void)
class myAdhocWifiMac : public AdhocWifiMac                                                                                               {
{                                                                                                                                                                 static TypeId tid = TypeId ("ns3::myAdhocWifiMac")
public:                                                                                                                                                         .SetParent<AdhocWifiMac> ()
  static TypeId GetTypeId (void);                                                                                                                   .AddConstructor<myAdhocWifiMac> ()
  myAdhocWifiMac ();                                                                                                                                   ;
  virtual ~myAdhocWifiMac ();                                                                                                                        return tid;
};                                                                                                                                                                  }
}                                                                                                                                                                   }
#endif /* MYADHOC_WIFI_MAC_H */

but when i run i have this error :  erreur: expected constructor, destructor, or type conversion before ‘(’ token
I don't find a solution for this problem, please help me.

Konstantinos

unread,
Mar 7, 2014, 8:35:45 AM3/7/14
to ns-3-...@googlegroups.com
Hi,

As the output suggests you do not have a constructor implementation.
Either implicit implementation of the default myAdhocWifiMac in the .cc file or just an empty implementation in the .h file (myAdhocWifiMac() { } )

Belkneni Maroua

unread,
Mar 7, 2014, 11:18:57 AM3/7/14
to ns-3-...@googlegroups.com
hi,
i added the constructor but i still have the same error, any suggestions?? 

Francisco Eduardo Balart Sanchez

unread,
May 25, 2017, 6:52:16 PM5/25/17
to ns-3-users
It happening to me too, even with the empty constructor
It seems that when in the *.h file you add the 

NS_LOG_COMPONENT_DEFINE ("foo");

the build some how complains about a constructor of "foo" in the *.h file

In file included from ./ns3/wifi-module.h:35:0,
                 from src/wifi/bindings/ns3module.h:78,
                 from src/wifi/bindings/ns3module.cc:1:
./ns3/my_file.h:38:25: error: expected constructor, destructor, or type conversion before ‘(’ token NS_LOG_COMPONENT_DEFINE ("foo");


This does not happen for  *.cc file for example in the class aodv-neighbor.cc

#include "aodv-neighbor.h"
#include "ns3/log.h"
#include <algorithm>


namespace ns3
{
  
NS_LOG_COMPONENT_DEFINE ("AodvNeighbors");

namespace aodv
{
Neighbors::Neighbors (Time delay) : 

AodvNeighbors does not exist in the whole aodv model  but when i did a grep i got this

balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/src/aodv$ grep -rin AodvNeighbors *
bindings/modulegen__gcc_LP64.py:706:    register_Ns3AodvNeighbors_methods(root_module, root_module['ns3::aodv::Neighbors'])
bindings/modulegen__gcc_LP64.py:707:    register_Ns3AodvNeighborsNeighbor_methods(root_module, root_module['ns3::aodv::Neighbors::Neighbor'])
bindings/modulegen__gcc_LP64.py:8273:def register_Ns3AodvNeighbors_methods(root_module, cls):
bindings/modulegen__gcc_LP64.py:8326:def register_Ns3AodvNeighborsNeighbor_methods(root_module, cls):
Binary file bindings/modulegen__gcc_LP64.pyc matches
bindings/modulegen__gcc_ILP32.py:706:    register_Ns3AodvNeighbors_methods(root_module, root_module['ns3::aodv::Neighbors'])
bindings/modulegen__gcc_ILP32.py:707:    register_Ns3AodvNeighborsNeighbor_methods(root_module, root_module['ns3::aodv::Neighbors::Neighbor'])
bindings/modulegen__gcc_ILP32.py:8273:def register_Ns3AodvNeighbors_methods(root_module, cls):
bindings/modulegen__gcc_ILP32.py:8326:def register_Ns3AodvNeighborsNeighbor_methods(root_module, cls):
model/aodv-neighbor.cc:37:NS_LOG_COMPONENT_DEFINE ("AodvNeighbors");


The AodvNeighbors its mentioned in the bindings so my hunch is that it has to do obviously with the build, and 
that the logging directive

NS_LOG_COMPONENT_DEFINE 
("foo");


only should be used in *.cc files, i actually observed that is not used in *.h files

Again hte empty definition of the constructor didn't work
For my class i only need a class with attributes so i don't have a *.cc file and defined the empty constructor, got same error

not sure if there is a workaround for this

Francisco Eduardo Balart Sanchez

unread,
May 25, 2017, 7:07:22 PM5/25/17
to ns-3-users
Maroua, let me correct my self and complement the answer

first the use of the logging directive 

NS_LOG_COMPONENT_DEFINE ("foo");

Needs to be used  after the ns3 namespace


Then to use a NS_LOG directive the simple but not so obvious for newbies is to add the ns3 log component with

#include "ns3/log.h"

In your *.h file and it will compile, it did with mine an i'm using ns3.25

Hope it helps

regards

Eduardo Balart
Reply all
Reply to author
Forward
0 new messages