Quote Originally Posted by Darkroman View Post
OK, so I changed apple& to fruit&, and I got multiple definition errors having to do with apple, banana, or melon. After that I just got rid of the objects all together. Now it's giving me a "expected primary-expression before '.' error (yes I changed apple.name to fruit.name) in my main.cpp. If it's not one problem, it's the next. I'm thinking it has to do with scoping somehow, but I'm not sure how to alleviate it. However, changing my code around like that is not what I want to do. I want to know if there's a way to make the program that I wrote above to work as intended. I am really stuck, and I can't seem to find any information on how to alleviate this problem.
Multiple definitions will occur if more than one source file includes your header.

Move the definitions of apple, banana, and melon out of the header file, and place them in exactly ONE .source file.

To illustrate, in the header.
Code:
#ifndef GUARD_fruit_struct_h
#define GUARD_fruit_struct_h

// fruit_struct.h

#include <string>

struct fruit {
    std::string name;
    int weight;
    float price;
};                          //  note the instances aren't being defined here

void apple_f(fruit &);

#endif
and, in one and only one of the source (for example, .cpp) files, define them....
Code:
#include "fruit_struct.h"

//    the definitions

fruit apple, banana, melon;
This assumes apple, banana, and melon only need to be used in one source file. If you need them in more than one source, add this line to the header (and still use ONE source file as above).
Code:
extern fruit apple, banana, melon;
This line is a declaration, not a definition. The extern keyword specifies that apple, banana, and melon are defined somewhere else, as above.