Bug 1505 - Compilation error when manipulating with ns3::Time
Compilation error when manipulating with ns3::Time
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: network
ns-3-dev
All All
: P5 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-18 11:30 EDT by Kirill Andreev
Modified: 2015-10-27 19:44 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kirill Andreev 2012-09-18 11:30:55 EDT
I have written a simple example in a scratch directory:


#include "ns3/nstime.h"
#include "ns3/data-rate.h"

using namespace ns3;

int main ()
{
  Time t1 = MilliSeconds (20);
  Time t2 = Time (t1 * 2);
  std::cout << t2 << std::endl;
  return 0;
}


Which can not be compiled when s3/data-rate.h. The problem is caused by the following: double operator* (const DataRate& lhs, const Time& rhs);

This makes compiler confused and the following error occures:

../scratch/time-example.cc: В функции «int main()»:                                                                                                                                                                              
../scratch/time-example.cc:9:24: ошибка: ambiguous overload for «operator*» in «t1 * 2»
../scratch/time-example.cc:9:24: замечание: candidates are:
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, const ns3::int64x64_t&)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, double)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, signed char)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, short int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long long int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, unsigned char)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, short unsigned int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, unsigned int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long unsigned int)
./ns3/int64x64.h:73:1: замечание: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long long unsigned int)
./ns3/data-rate.h:129:8: замечание: double ns3::operator*(const ns3::Time&, const ns3::DataRate&)


Making a DataRate constructor as explicit fixes this problem but makes the build as failed:

diff -r c6eef7627ca4 src/network/utils/data-rate.h
--- a/src/network/utils/data-rate.h     Wed Jun 06 23:30:07 2012 -0700
+++ b/src/network/utils/data-rate.h     Tue Sep 18 19:29:09 2012 +0400
@@ -80,7 +80,7 @@
    * non-trivial bitrate available.
    * \param bps bit/s value
    */
-  DataRate (uint64_t bps);
+  explicit DataRate (uint64_t bps);
   DataRate (std::string rate);
 
   bool operator <  (const DataRate& rhs) const;




I have tested the same scenario with ns-3.14, the explicit contructor did not kill the build.
Comment 1 Kirill Andreev 2012-09-18 11:33:06 EDT
Sorry for the error message with russian words.

../scratch/time-example.cc: In function 'int main()':                                                                                                                                                                            
../scratch/time-example.cc:9:24: error: ambiguous overload for 'operator*' in 't1 * 2'
../scratch/time-example.cc:9:24: note: candidates are:
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, const ns3::int64x64_t&)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, double)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, signed char)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, short int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long long int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, unsigned char)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, short unsigned int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, unsigned int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long unsigned int)
./ns3/int64x64.h:73:1: note: ns3::int64x64_t ns3::operator*(const ns3::int64x64_t&, long long unsigned int)
./ns3/data-rate.h:129:8: note: double ns3::operator*(const ns3::Time&, const ns3::DataRate&)
Comment 2 Peter Barnes 2014-03-02 04:11:47 EST
I believe this has been fixed by:

Bug 1856 Patch r10637 67601c471c22
http://code.nsnam.org/ns-3-dev/rev/67601c471c22

Kirill could you please confirm that this is fixed?
Comment 3 natale.patriciello 2015-10-27 06:52:33 EDT
Works for me, tested with ns 3.24 and ns-3-dev . Can be closed.