Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Confusing code

Confusing code

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rejeesh
    wrote on last edited by
    #1

    #include using namespace std; struct C; struct D { void operator*(D) { cout << "one\n"; } } C; struct E { void operator*(E) { cout << "two\n"; } } F; struct F; int main(){ C* C; F* F; return 0; } I got the above code from a C++ site. This code prints "one" "two" on the screen. Can anybody explain why is it printing so? :confused: :confused: :confused: void (*p[10]) (void (*)());

    T 1 Reply Last reply
    0
    • R Rejeesh

      #include using namespace std; struct C; struct D { void operator*(D) { cout << "one\n"; } } C; struct E { void operator*(E) { cout << "two\n"; } } F; struct F; int main(){ C* C; F* F; return 0; } I got the above code from a C++ site. This code prints "one" "two" on the screen. Can anybody explain why is it printing so? :confused: :confused: :confused: void (*p[10]) (void (*)());

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      C* C looks like declaration of pointer to C, but it isn't. It's a call to operator* overloaded in struct D. To make code clearer, put the space between first 'C' and asterisk - you'll see that this is an expression, not the declaration: C * C; This also applies to F* F (or rather F * F). Tomasz Sowinski -- http://www.shooltz.com.pl

      R 1 Reply Last reply
      0
      • T Tomasz Sowinski

        C* C looks like declaration of pointer to C, but it isn't. It's a call to operator* overloaded in struct D. To make code clearer, put the space between first 'C' and asterisk - you'll see that this is an expression, not the declaration: C * C; This also applies to F* F (or rather F * F). Tomasz Sowinski -- http://www.shooltz.com.pl

        R Offline
        R Offline
        Rejeesh
        wrote on last edited by
        #3

        Thank u very much. Its only after ur reply I am thinking that C* C; is not a pointer declaration. Now, everything is quite clear and very simple. Thank u once again. :-O void (*p[10]) (void (*)());

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups