Complain:
lesson2.cpp:9: warning: ISO C++ forbids declaration of ‘main’ with no type
My Code:
Code:
#include <iostream>
using namespace std;
struct weapons_guns {
int sniper,assaultrifle,shotgun; // arsenal
};
main() {
weapons_guns guns; // activates? the structure weapons_guns as 'guns'
weapons_guns *ptr; // defines the pointer weapon_guns.ptr or does it define weapons_guns as *ptr?
guns.sniper = 100; // sets the weapons_guns.sniper too 100 ( ment to reflect price )
ptr = &guns; // sets the pointer(ptr) too weapons_guns aka'guns' structure?
cout<< ptr->sniper; // takes the output from weapons_guns.sniper with a pointer
// does it use 'weapons_guns' as *ptr too call weapons_guns.sniper?
cin.get();
}
Original, compiles fine:
Code:
#include <iostream>
using namespace std;
struct xampl {
int x;
};
int main()
{
xampl structure;
xampl *ptr;
structure.x = 12;
ptr = &structure; // Yes, you need the & when dealing with structures
// and using pointers to them
cout<< ptr->x; // The -> acts somewhat like the * when used with pointers
// It says, get whatever is at that memory address
// Not "get what that memory address is"
cin.get();
}
as you can see they are very similar, i can't narrow down why I get that error..