Thread: Explanation required (Why?)

  1. #1
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46

    Explanation required (Why?)

    typedef char * PSTR;
    void Print (char *szToPrint);
    void Print (PSTR szToPrint);

    "The preceding two fxns have identical arguments. PSTR is an acronym for type "char*". In Member scope, this code generates an error."

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    PSTR is typedef'ed to mean char *. So the second function prototype is taken to mean this:

    Code:
    void Print (char *szToPrint);
    Problem: The first function prototype is identical to this.

    Member scope.... This has to do if you're writing functions for classes. The compiler freaks out if you make the above type of function declarations that resolve to the same signature.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    PSTR is an acronym for type "char*".
    No, it's an alias. Meaning you can go through your code and replace every occurence of PSTR with char* and the meaning will not change. (OK, that's not quite true, but the edge case where it isn't is not important right now.)

    As for the member scope thing ...

    Code:
    void foo();
    void foo();
    Is this code valid? Yes. Both lines are declarations for the same function. A function may be declared more than once.

    But in member scope:
    Code:
    class bar {
      void foo();
      void foo();
    };
    it is invalid. For some reason, declaring the same member function twice is not allowed.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46
    Those really helped

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Lvalue required error
    By eklavya8 in forum C Programming
    Replies: 5
    Last Post: 01-03-2009, 04:47 PM
  3. Linked Lists
    By Bleu_Cheese in forum C++ Programming
    Replies: 13
    Last Post: 12-21-2007, 09:17 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM