space after dot . member access operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi:

wrote this code to explain template specialization and accidentally made a typo in the last line of the code.

      by.         print ();

The code compiles without any issue and runs as expected.

Can the experienced folks share what could i be missing here ?

// -------

#include <iostream>

template <typename T> class box {

public:
      T a_;
      T b_;

public:
      auto swap  () -> void;
      auto print () -> void;
};


template <typename T> auto box<T>::swap () -> void {

      T tmp {a_};
      a_ = b_;
      b_ = tmp;
}


template <typename T> auto box<T>::print () -> void {

      std::cout << a_ << '\n';
}


template <> auto box<bool>::print () -> void {

      std::cout << (a_ ? "true" : "false") << '\n';
}


// -----------------------------------------------

auto main () -> int {

      box <int> bx {3, 7};

      std::cout << "a = " << bx.a_ << ", b = " << bx.b_ << '\n';

      bx.swap ();

      std::cout << "a = " << bx.a_ << ", b = " << bx.b_ << '\n';

      bx.print ();


      box <bool> bb { false, true };

      bb.print ();

      box <bool> by { 1, 0 };

      by.         print ();


return 0;
}


Here are the GCC toolchain details

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/gcc/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../../../src/gcc/configure --prefix=/opt/gcc --datadir=/opt/gcc/doc --htmldir=/opt/gcc/doc --enable-languages=c,c++ --enable-bootstrap --disable-multilib --enable-libstdcxx --enable-shared --enable-host-shared --enable-plugin --enable-default-pie --enable-ld=yes --with-gnu-ld --with-linker-hash-style=gnu --with-isl=/opt/isl --enable-linker-build-id --enable-clocale=gnu --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libssp --enable-lto --enable-gcov --enable-vtable-verify --enable-__cxa_atexit --enable-threads=posix --enable-tls --enable-werror --disable-unwind-exceptions --enable-install-libiberty --enable-c++-tools --with-bugurl=https://bugs.strikr.io/
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.0.1 20210320 (experimental) (GCC)


Is there any specific reason as why the space between the dot (.) and member function, print () in this case doesnot seem to matter ?


warm regards
Saifi.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux