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..


struct car{
int year;};


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

using namespace std;

int main(int argc, char *argv[])
    car c;
    return EXIT_SUCCESS;


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

extern car c;

class test{

Recommended Answers

All 6 Replies

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

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.

err.. do you mind give me some example?


#ifndef _MYHEADER_H
#define _MYHEADER_H

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


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.