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. ATL / WTL / STL
  4. WCHAR argument pointer Resolved

WCHAR argument pointer Resolved

Scheduled Pinned Locked Moved ATL / WTL / STL
c++comdata-structureshelpquestion
3 Posts 2 Posters 2 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.
  • B Offline
    B Offline
    bkelly13
    wrote on last edited by
    #1

    The dot H file contains:

    = L"C:\\LOG_FILES\\";

    const WCHAR DEFAULT_FILENAME_PREFIX[] = L"Log_File_";

    The dot CPP file contains

    C_Log_Writer::C_Log_Writer(
    const WCHAR *new_directory_name = &DEFAULT_DlRECTORY,
    const WCHAR *new_name_prefix = &DEFAULT_FILENAME_PREFIX[0] )
    { ... }

    The new_directory_name lines does not compile and produces the error:

    Error 1 error C2440: 'default argument' : cannot convert from 'const WCHAR (*)[14]' to 'const WCHAR *' e:\code_tests\common_code_dll\c_log_writer\c_log_writer.cpp 73 1 C_Log_Writer

    I thought new_directory_name would be a pointer that would by default point to the first character of the array. Why is that thinking wrong?

    Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

    Richard Andrew x64R 1 Reply Last reply
    0
    • B bkelly13

      The dot H file contains:

      = L"C:\\LOG_FILES\\";

      const WCHAR DEFAULT_FILENAME_PREFIX[] = L"Log_File_";

      The dot CPP file contains

      C_Log_Writer::C_Log_Writer(
      const WCHAR *new_directory_name = &DEFAULT_DlRECTORY,
      const WCHAR *new_name_prefix = &DEFAULT_FILENAME_PREFIX[0] )
      { ... }

      The new_directory_name lines does not compile and produces the error:

      Error 1 error C2440: 'default argument' : cannot convert from 'const WCHAR (*)[14]' to 'const WCHAR *' e:\code_tests\common_code_dll\c_log_writer\c_log_writer.cpp 73 1 C_Log_Writer

      I thought new_directory_name would be a pointer that would by default point to the first character of the array. Why is that thinking wrong?

      Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Because you're trying to assign a pointer-to-a-pointer to a pointer:

      const WCHAR *new_directory_name = &DEFAULT_DlRECTORY

      should be

      const WCHAR *new_directory_name = DEFAULT_DlRECTORY

      The difficult we do right away... ...the impossible takes slightly longer.

      B 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Because you're trying to assign a pointer-to-a-pointer to a pointer:

        const WCHAR *new_directory_name = &DEFAULT_DlRECTORY

        should be

        const WCHAR *new_directory_name = DEFAULT_DlRECTORY

        The difficult we do right away... ...the impossible takes slightly longer.

        B Offline
        B Offline
        bkelly13
        wrote on last edited by
        #3

        And that is because DEFAULT_DlRECTORY is an array and passing it as an argument means the address of the first character is passed. Ok, I must confess to being ate up with the dumb ass there. Thank you for taking the time for a gentle kick in the butt.

        Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

        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