| | |
Require help to solve!!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 19
Reputation:
Solved Threads: 0
Presently my files are:
testA.h
testA.C
testB.h
testB.C
I am able to compile g++ -c testA.C without any problems.
But g++ -c testB.C is giving multiple declarations error!!
How to fix this issue??
Thanks!!!
testA.h
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #include "testB.h" class TestA { public: TestA(); int id; TestB* b; void testPrint(); void test(); void set(TestB* t); };
C++ Syntax (Toggle Plain Text)
#include "testA.h" void TestA::testPrint() { printf("I am in class TestA\n"); } TestA::TestA() { id = 1; } void TestA::set(TestB* t) { b = t; } void TestA::test() { printf("My ID is: %d and the other ID is: %d\n", this->id, b->id); }
C++ Syntax (Toggle Plain Text)
#include <stdio.h> class TestA; class TestB { public: TestB(); TestA* a; int id; void testPrint(); void test(); void set(TestA* t); };
C++ Syntax (Toggle Plain Text)
#include "testB.h" void TestB::testPrint() { printf("I am in class TestB\n"); } TestB::TestB() { id = 2; } void TestB::set(TestA* t) { a = t; } void TestB::test() { printf("My ID is: %d and the other ID is: %d\n", this->id, a->id); }
I am able to compile g++ -c testA.C without any problems.
But g++ -c testB.C is giving multiple declarations error!!
How to fix this issue??
Thanks!!!
•
•
Join Date: Nov 2007
Posts: 19
Reputation:
Solved Threads: 0
Sorry!!!
It wont work that way since I have already included testB.h in testA.h and so can't include again the other way.
I initially posted this problem but then someone corrected me and now I am able to compile testA.C but not testB.C
If you go through the entire thread trail then you will come to know!!!
It wont work that way since I have already included testB.h in testA.h and so can't include again the other way.
I initially posted this problem but then someone corrected me and now I am able to compile testA.C but not testB.C
If you go through the entire thread trail then you will come to know!!!
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
You should always include the header when you want to use it's class to avoid multiple inclusion add the following code.
And remove testA declaration in testB.h
#ifdef TESTB_H #define TESTB_H //class declaration #endif
And remove testA declaration in testB.h
All i've got is a slice of pi
•
•
Join Date: Nov 2007
Posts: 19
Reputation:
Solved Threads: 0
Ok...
My files are like this now:
testA.h
testB.h
On compiling g++ -Wall -c testA.C
testB.h:12: error: ‘TestA’ has not been declared
testB.h:17: error: ISO C++ forbids declaration of ‘TestA’ with no type
testB.h:17: error: expected ‘;’ before ‘*’ token
On compiling g++ -Wall -c testB.C
testA.h:12: error: ‘TestB’ has not been declared
testA.h:17: error: ISO C++ forbids declaration of ‘TestB’ with no type
testA.h:17: error: expected ‘;’ before ‘*’ token
Please help to fix this issue!!!
My files are like this now:
testA.h
C++ Syntax (Toggle Plain Text)
#ifndef __TESTA_H #define __TESTA_H #include <stdio.h> #include "testB.h" class TestA { public: TestA(); void testPrint(); void test(); void set(TestB* t); int getID(); private: int id; TestB* b; }; #endif
C++ Syntax (Toggle Plain Text)
#ifndef __TESTB_H #define __TESTB_H #include <stdio.h> #include "testA.h" class TestB { public: TestB(); void testPrint(); void test(); void set(TestA* t); int getID(); private: int id; TestA* a; }; #endif
On compiling g++ -Wall -c testA.C
testB.h:12: error: ‘TestA’ has not been declared
testB.h:17: error: ISO C++ forbids declaration of ‘TestA’ with no type
testB.h:17: error: expected ‘;’ before ‘*’ token
On compiling g++ -Wall -c testB.C
testA.h:12: error: ‘TestB’ has not been declared
testA.h:17: error: ISO C++ forbids declaration of ‘TestB’ with no type
testA.h:17: error: expected ‘;’ before ‘*’ token
Please help to fix this issue!!!
Last edited by abhishek2301; May 29th, 2009 at 3:45 pm.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
OK last try
CPP Syntax (Toggle Plain Text)
class TestA; #ifndef __TESTA_H #define __TESTA_H #include <stdio.h> #include "testB.h" class TestA { public: TestA(); void testPrint(); void test(); void set(TestB* t); int getID(); private: int id; TestB* b; }; #endif
All i've got is a slice of pi
![]() |
Similar Threads
- Send data on a serial port (C++)
- Win XP stop error (Windows NT / 2000 / XP)
- Internet Explorer & Windows Explorer (desktop shortcuts) Won't Load! (Viruses, Spyware and other Nasties)
- new window in Internet Explorer is always blank (Web Browsers)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- 35 processes, need to trim the fat (Viruses, Spyware and other Nasties)
- please help been at my pc for hours still cannot solve problem (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Please Hlpe me, lojec erooe
- Next Thread: image in picture control not displayed properly after moving
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





