I am trying to figure out how to declare an object of a struct, as well as assign values to its members. The issue is that I can't manipulate or use that struct in other files, or rather the struct is not recognized in the other files. Below is an example on what I mean.
1 2 3 4 5 6 7 8 9 10 11
|
//-----------------------------------------------
// Structures.h
//-----------------------------------------------
struct OBJECT {
float cost;
};
OBJECT pencil;
pencil.cost = 0.44;
| |
1 2 3 4 5 6 7 8
|
//-----------------------------------------------
// Main.h
//-----------------------------------------------
#include "Structures.h"
float total;
total = pencil.cost * 24;
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//-----------------------------------------------
// Main.cpp
//-----------------------------------------------
#include <iostream>
#include "Main.h"
using namespace std;
int main()
{
cout << "Cost of 24 pencils: " << total;
return 0;
}
| |
structures.h(11) : error C2143: syntax error : missing ';' before '.'
structures.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
structures.h(11) : error C2371: 'pencil' : redefinition; different basic types
structures.h(9) : see declaration of 'pencil'
main.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.h(8) : error C2371: 'total' : redefinition; different basic types
main.h(6) : see declaration of 'total'
main.h(8) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
main.cpp(11) : error C2088: '<<' : illegal for class