C++ else if scope error and enum CommandLine parse issue in ns-3

25 views
Skip to first unread message

압둘하미드이드리스

unread,
Jul 6, 2025, 8:53:40 PMJul 6
to ns-3-...@googlegroups.com
Hello,

I was working on an ns-3.45 simulation (using CMake, g++ 13, Ubuntu 22.04). Having tried to implement a function to configure different privacy schemes for vehicles using
an enum SchemeType.

When building, I got these errors:

[ 99%] Building CXX object scratch/CMakeFiles/scratch_ns3_privacy_comparison.dir/ns3_privacy_comparison.cc.o
/home/idrab/ns-3.45/scratch/ns3_privacy_comparison.cc: In function ‘void InstallVehicleApp(ns3::NodeContainer, SchemeType)’:
/home/idrab/ns-3.45/scratch/ns3_privacy_comparison.cc:46:11: error: ‘else’ without a previous ‘if’
   46 |         } else if (scheme == BASELINE_CRYPTO_ONLY) {
      |           ^~~~
...
/home/idrab/ns-3.45/scratch/ns3_privacy_comparison.cc:47:51: error: ‘i’ was not declared in this scope
   47 |             NS_LOG_INFO("[BASELINE1] Vehicle " << i << ": Sending ECC signed pseudonym at " << start << "s");
...
/home/idrab/ns-3.45/scratch/ns3_privacy_comparison.cc:48:41: error: ‘start’ was not declared in this scope
   48 |             Simulator::Schedule(Seconds(start), [](){
...
/home/idrab/ns-3.45/scratch/ns3_privacy_comparison.cc:59:1: error: expected declaration before ‘}’ token
   59 | }
/home/idrab/ns-3.45/src/core/model/command-line.h:811:9: error: no match for ‘operator>>’ (operand types are ‘std::istringstream’ and ‘SchemeType’)


My questions:

How should I properly structure the else if so it compiles inside a loop over vehicles?

Why are i and start undeclared inside my else if blocks?

How can I fix the operator>> error when using CommandLine with my enum SchemeType?


Gabriel Ferreira

unread,
Jul 7, 2025, 6:42:56 AMJul 7
to ns-3-users
Based on the error message, I would guess your code looks something like this

void InstallVehicleApp(ns3::NodeContainer, SchemeType)
{
...// undeclared start
...// missing if to start if-else
...{
...}
...else if()
...{
......for (int j = 0; j < max; j++) // should be i
......{
.........NS_LOG_INFO("[BASELINE1] Vehicle " << i << ": Sending ECC signed pseudonym at " << start << "s");
.........Simulator::Schedule(Seconds(start), [](){
.........}
.........// missing ); to close Schedule
......}
...}

압둘하미드이드리스

unread,
Jul 7, 2025, 8:13:03 AMJul 7
to ns-3-...@googlegroups.com
Thanks I will check that out.
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/6ab537c1-8410-4207-9592-a01fd504cf33n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages