Thread: Struct "no member named" error msg

  1. #1
    Registered User
    Join Date
    Nov 2020

    Exclamation Struct "no member named" error msg

    I am learning C and getting into structures, but I am getting a lot of errors I don't know how to fix.

    I am using xCode, and I've made a header file. This is what I have in my header file:

    struct player {
    int playerID;
    char rank[25];
    char fieldType[25];
    int level;

    The first error I get is "Type 'struct player' has incompatible definitions in different translation units".

    I've already included the header file and <sys/player.h> in the main editor. So far, this is what I have in my main editor:

     #include <stdio.h>
    #include <stdlib.h>
    #include "Header.h" (this is the name of my header file)
    #include <sys/player.h>
    int main () {
    struct player newbie;
    newbie.playerID = 10;
    printf("Enter the RANK of player 10: ");
    printf("\nEnter the FIELD TYPE of player 10");
    printf("\nEnter the LEVEL of player 10");
    return 0;

    Then I got these errors:
    No member named 'playerID' in 'struct player'
    No member named 'rank' in 'struct player'
    No member named 'fieldType' in 'struct player'
    No member named 'level' in 'struct player'

    What am I missing?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    What exactly is <sys/player.h>? I'd guess that you may have installed a different version of your header file as a system header under a sys folder, and hence your new header file (Header.h) has a definition of struct player than doesn't match the old one. If this is so, then I would recommend deleting that system installed custom header and only including Header.h (which you probably want to rename to player.h).

    By the way, gets is inherently vulnerable to buffer overflow and is obsolescent anyway. Use fgets instead and just check if the newline has been stored, and if so, replace it with a null character.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: 'struct SPPS48' has no member named 'M1'
    By uzmeed in forum C++ Programming
    Replies: 1
    Last Post: 01-04-2018, 04:14 PM
  2. Replies: 12
    Last Post: 05-17-2010, 08:12 PM
  3. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  4. Replies: 1
    Last Post: 04-17-2008, 07:45 PM
  5. "ambiguous access to class/struct/union member"
    By Mr_Jack in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2003, 12:15 PM

Tags for this Thread