i have problem only declaring struct variable. i declare a struct in struct.h file and i wan main.c and class.h also using the same variable. But the class.h file say the struct is undeclare..

example:
struct.h

struct car{
int year;};

main.c

#include <cstdlib>
#include <iostream>
#include "struct.h"
#include "class.h"

using namespace std;

int main(int argc, char *argv[])
{
    car c;
    system("PAUSE");
    return EXIT_SUCCESS;
}
}

class.h

#include <cstdlib>
#include <iostream>
using namespace std;

extern car c;

class test{
c.year=10;};

Edited 6 Years Ago by kiwihaha: n/a

If you have not included class.h in your project, include "struct.h" in "class.h" instead of main.

i got problem if include .h file in a .h file

You can always include .h files in .h files. & always use include-guards for your headers. Did you remove #include stament in main? If no remove it as it will create an error of multiple declaration of struct car.

Edited 6 Years Ago by nbaztec: n/a

Sure.

#ifndef _MYHEADER_H
#define _MYHEADER_H
/*
Code
*/
#endif

This ensures that header file is "included" only once in a project.

This question has already been answered. Start a new discussion instead.