Ok im creating a program to make a database of people associated with a university, these people are called universitypeople, i have another file universitydatabase which stores all these people and will edit their information... well im having these errors when i type make... the errors could be class based or pointer based im not sure, but ill include a handful of the files im using for this thread... any help or suggestions would be appreciated

g++ -c universitydatabase.cpp
universitydatabase.cpp: In member function `void UNIVERSITYDATABASE::addNewPerson(UNIVERSITYPERSON*)':
universitydatabase.cpp:18: error: request for member `fullname' in `newMember->node::person', which is of non-class type `UNIVERSITYPERSON*'
universitydatabase.cpp:19: error: request for member `fullname' in `newPerson', which is of non-class type `UNIVERSITYPERSON*'
universitydatabase.cpp:20: error: cannot convert `UNIVERSITYPERSON*' to `node*' in assignment
universitydatabase.cpp:24: error: request for member `fullname' in `newMember->node::person', which is of non-class type `UNIVERSITYPERSON*'
universitydatabase.cpp:25: error: request for member `fullname' in `newPerson', which is of non-class type `UNIVERSITYPERSON*'
universitydatabase.cpp:27: error: cannot convert `UNIVERSITYPERSON*' to `node*' in assignment
make: *** [universitydatabase.o] Error 1

//universitydatabase.h

#ifndef UNIVERSITYDATABASE_H
#define UNIVERSITYDATABASE_H

#include "universityperson.h"

typedef struct node {
  UNIVERSITYPERSON *person;
  struct node *next;
};

class UNIVERSITYDATABASE {

  struct node *database;

public:
  UNIVERSITYDATABASE() { database = NULL; }
  void addNewPerson( UNIVERSITYPERSON *newPerson );
  node *getDatabase();

};
#endif

//universitydatabase.cpp

#include "universitydatabase.h"

void UNIVERSITYDATABASE::addNewPerson( UNIVERSITYPERSON *newPerson ){

  node *newMember, *temp, *temp2;
  if( database == NULL ){
    database->person = newPerson;
    database->next = NULL;
  }
  else{
    newMember = database;
    if( strcmp( toupper( atoi( newMember->person.fullname ) ), //error points here (tried atoi but didnt change error)
                toupper( newPerson.fullname ) ) = 1 ){ //error points here
        temp = newMember->person;
        newMember->person = newPerson;
        newMember->next = temp;
    }
    if( strcmp( toupper( newMember->person.fullname), //error points here
                toupper( newPerson.fullname ) ) = -1 ){ //error points here
      temp = newMember->next;
      newMember->next = newPerson;
    }
    temp = new node;
    temp->person = newPerson;
    temp->next = NULL;
    newMember->next = temp;
  }

}

node* UNIVERSITYDATABASE::getDatabase(){
  return database;
}

// universityperson.h


#ifndef UNIVERSITYPERSON_H
#define UNIVERSITYPERSON_H

#include "lib.h"

class UNIVERSITYPERSON{

  string fullname, id;
  bool employee, student, alumnus, position;

 public:
  UNIVERSITYPERSON(){
    fullname = "No Name";
    id = "00000000";
    employee = 0;
    student = 0;
    alumnus = 0;
    position = 0;
    cout << toString();
  };

  string getFullName();
  string getID();
  string getPosition();
  string toString();

  ~UNIVERSITYPERSON(){
    cout << "Universityperson destructor: University Person is " << toString();
  };
};
#endif

//universityperson.cpp


#include "universityperson.h"

string UNIVERSITYPERSON::getFullName(){
  return fullname;
}

string UNIVERSITYPERSON::getID(){
  return id;
}

string UNIVERSITYPERSON::getPosition(){
  if( !position )
    return( " " );
  if( employee )
    return( "Employee" );
  if( student )
    return( "Student" );
  if( alumnus )
    return( "Alumnus" );
}

string UNIVERSITYPERSON::toString(){
  return( fullname + ", " + id + ", " + getPosition() + "\n" );
}

any other files you want i can put on here but im fairly positive the error is on these files

Recommended Answers

All 7 Replies

I'm not absolutely clear on what you are trying to do with the atoi on that line 39. toUpper only works with one character at a time so you'd have to go through each element. The errors you pasted in at the top don't seem to have anything to do with these that you marked in the code, you may need an additional layer of dereferencing since your struct member is a pointer to a class, but I am not positive of that.

newMember->person is a pointer. You cannot apply a dot to it. Dot is only applicable to instances. Replace a dot with an arrow in all offending lines, as in newPerson->fullname That was purely syntactical. The last error (which I believe refers to line 42 in the posted code) needs more attention. What are you trying to do there, in plain English please?

my new files are as follows but first here are my new errors

g++ -c universitydatabase.cpp
universitydatabase.cpp: In member function `void UNIVERSITYDATABASE::addNewPerson(UNIVERSITYPERSON*)':
universitydatabase.cpp:18: error: `person' was not declared in this scope
universitydatabase.cpp:19: warning: taking address of temporary
universitydatabase.cpp:24: error: `person' was not declared in this scope
universitydatabase.cpp:25: warning: taking address of temporary
make: *** [universitydatabase.o] Error 1

//universitydatabase.h
#ifndef UNIVERSITYDATABASE_H
#define UNIVERSITYDATABASE_H

#include "universityperson.h"

typedef struct node {
  UNIVERSITYPERSON *person;
  struct node *next;
};

class UNIVERSITYDATABASE {

  node *database;

 public:
  UNIVERSITYDATABASE() { database = NULL; };
  void addNewPerson( UNIVERSITYPERSON *newPerson );
  node *getDatabase();

};
#endif

//universitydatabase.cpp

#include "universitydatabase.h"

void UNIVERSITYDATABASE::addNewPerson( UNIVERSITYPERSON *newPerson ){

  node *newMember, *temp, *temp2;
  if( database->person == NULL ){
    database->person = newPerson;
    database->next = NULL;
  }
  else{
    newMember = database;
    if( strcmp( newMember->*person.getFullName() ,   // Attempting to sort alphabetically when
                &(*newPerson).getFullName() ) = 1 ){        // new people are added
        temp->*person = newMember->person;            // temp will equal current person
        newMember->person = newPerson;                   // current person equals new person
        newMember->next = temp;                                 // next equals temp
    }
    if( strcmp( newMember->*person.getFullName(),   // same as above sorting alphabetically
                &(*newPerson).getFullName() ) = -1 ){
      temp = newMember->next;                                    // temp equals current next
      temp2->*person = newPerson;                             // second temp equals new person
      temp2->next = temp;                                             // second temp next equals first temp
      newMember->next = temp2;                                  // next equals second temp
    }
    temp = new node;                    //will delete this code
    temp->person = newPerson;   // delete
    temp->next = NULL;                 // delete
    newMember->next = temp;      // delete
  }

}

node* UNIVERSITYDATABASE::getDatabase(){
  return database;
}

//universityperson.h


#ifndef UNIVERSITYPERSON_H
#define UNIVERSITYPERSON_H

#include "lib.h"

class UNIVERSITYPERSON{

  string fullname, id;
  bool employee, student, alumnus, position;

 public:
  UNIVERSITYPERSON(){
    fullname = "No Name";
    id = "00000000";
    employee = 0;
    student = 0;
    alumnus = 0;
    position = 0;
    cout << toString();
  };

  string getFullName();
  void setFullName( string fullName );
  string getID();
  void setID( string ID );
  string getPosition();
  void setPosition( string Position );

  string toString();
  ~UNIVERSITYPERSON(){
    cout << "Universityperson destructor: University Person is " << toString();
  };
};
#endif

//universityperson.cpp


#include "universityperson.h"

string UNIVERSITYPERSON::getFullName(){
  return fullname;
}

void UNIVERSITYPERSON::setFullName( string fullName ){
  fullname = fullName;
}

string UNIVERSITYPERSON::getID(){
  return id;
}

void UNIVERSITYPERSON::setID( string ID ){
  id = ID;
}

string UNIVERSITYPERSON::getPosition(){
  if( !position )
    return( " " );
  if( employee )
    return( "Employee" );
  if( student )
    return( "Student" );
  if( alumnus )
    return( "Alumnus" );
}
void UNIVERSITYPERSON::setPosition( string Position ){
  if( Position == "EMPLOYEE" ){
    employee = 1;
    position = 1;
  }
 if( Position == "STUDENT" ){
   student = 1;
   position = 1;
 }
 if( Position == "Alumnus" ){
   alumnus = 1;
   position = 1;
 }
}

string UNIVERSITYPERSON::toString(){
  return( fullname + ", " + id + ", " + getPosition() + "\n" );
}

I took out the & before newPerson to get rid of the warnings, but i can't figure out how to fix the errors, person is a pointer to a universityperson so it doesnt make sense to me

newMember->person is a pointer. You cannot apply a dot to it. Dot is only applicable to instances. Replace a dot with an arrow in all offending lines, as in newPerson->fullname That was purely syntactical. The last error (which I believe refers to line 42 in the posted code) needs more attention. What are you trying to do there, in plain English please?

I changed the code to arrows like this

if( strcmp( newMember->*person->getFullName() ,
                (*newPerson).getFullName() ) = 1 ){
        temp->*person = newMember->person;
        newMember->person = newPerson;
        newMember->next = temp;
    }
    if( strcmp( newMember->*person->getFullName(),
                (*newPerson).getFullName() ) = -1 ){
      temp = newMember->next;
      temp2->*person = newPerson;
      temp2->next = temp;
      newMember->next = temp2;
    }

When i type newMember->person = newPerson im trying to make the universityperson of the newMember node equal the newPerson which comes into the function. then after that the next field of that node will equal the original newMember universityperson/ next field, so if the code works correctly I will have the new node of the linked list be earlier or later in regards to alphabetical order... any suggestions on how to go about this in a better way or how to fix the errors please respond asap

Why do you go into such complications as newMember->&(*person)->getFullName() , when newMember->person->getFullName() is enough? In fact, not just enough, but even correct.

if the code works correctly

I gather the code doesn't compile, so it is too early to guess how it works. Once you have an executable which you can run, we may start to debug the logic.

Nezachem is right. I was starting to post before and it went into the vortex. I was asking about your "lib.h" so I could compile the code, but I assume that it has your #includes in it. From your code it seems like you are missing the fact that (*object).memberfunction() is equivalent to object->memberfunction(). You also were setting your strcmp results = 1 rather than ==1.

Here are some changes I made to one of your if statements which can be easily applied to the other

if( strcmp( (newMember->person->getFullName()).c_str() ,
        (newPerson->getFullName()).c_str() ) == 1 ){        
       temp->person = newMember->person;           
        newMember->person = newPerson; 
  
etc.
}

I don't know if it will work for you as I didn't have main to test it with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.