473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

use of undefined type????

I have two classes(class A, class main). class main uses a pointer to
class A and class A uses a global pointer to main. My problem is I
keep getting these errors: :(

a.h(12) : error C2027: use of undefined type 'main'
a.h(4) : see declaration of 'main'
a.h(12) : error C2227: left of '->SomeDriver' must point to class/
struct/union/generic type

How do I fix this?

Thx ahead of time.
********
#include "main.h"
#include "A.h"

main *g_main = NULL;
int _tmain(int argc, _TCHAR* argv[])
{
g_main = new main;
g_main->a = new A;
g_main->a->Print();
g_main->a->SomeFunction();

return 0;
}
*********
#ifndef MAIN_H
#define MAIN_H
class A;
class main
{
public:
void SomeDriver()
{
printf ("driver called\n");
}
void PrintA()
{
a->Print();
}
A *a;
};
extern main *g_main;
#endif
*******
#ifndef A_H
#define A_H
class main;
class A
{
public:
void SomeFunction()
{
g_main->SomeDriver();
}
void Print()
{
printf ("Characters: a\n");
}
};
#endif

Jun 6 '07 #1
3 4110
Anonymous Infidel - Aborted Islam with a hanger wrote:
I have two classes(class A, class main). class main uses a pointer to
class A and class A uses a global pointer to main. My problem is I
keep getting these errors: :(

a.h(12) : error C2027: use of undefined type 'main'
a.h(4) : see declaration of 'main'
a.h(12) : error C2227: left of '->SomeDriver' must point to class/
struct/union/generic type

How do I fix this?
First off, you should probably rename your class from 'main' to smth
else. 'main' is the name of the function in your program that starts
its execution.
>
Thx ahead of time.
********
#include "main.h"
#include "A.h"

main *g_main = NULL;
int _tmain(int argc, _TCHAR* argv[])
There is no standard function _tmain.
{
g_main = new main;
g_main->a = new A;
g_main->a->Print();
g_main->a->SomeFunction();

return 0;
}
*********
#ifndef MAIN_H
#define MAIN_H
class A;
class main
{
public:
void SomeDriver()
{
printf ("driver called\n");
}
void PrintA()
{
a->Print();
Class 'A' hasn't been defined here yet. Consider pulling this
function out of the class definition into the translation unit.
}
A *a;
};
extern main *g_main;
#endif
*******
#ifndef A_H
#define A_H
class main;
class A
{
public:
void SomeFunction()
{
g_main->SomeDriver();
Although your 'A.h' is supposedly included after your 'main.h',
if it weren't, 'g_main' is undefined here. Consider pulling this
function out of the class definition into a translation unit.
}
void Print()
{
printf ("Characters: a\n");
}
};
#endif
Consider separating declarations and implementations of class
member functions. It's always a good idea for beginners.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 6 '07 #2
On 6/6/2007 3:59 PM, Anonymous Infidel - Aborted Islam with a hanger wrote:
I have two classes(class A, class main). class main uses a pointer to
class A and class A uses a global pointer to main. My problem is I
keep getting these errors: :(

a.h(12) : error C2027: use of undefined type 'main'
a.h(4) : see declaration of 'main'
a.h(12) : error C2227: left of '->SomeDriver' must point to class/
struct/union/generic type

How do I fix this?

[code snipped] see one of his other posts.
What's wrong with you?
Do you read answers to your posts?

S.
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Jun 6 '07 #3
On Jun 6, 7:08 am, Stefan Naewe <nos...@please.netwrote:
On 6/6/2007 3:59 PM, Anonymous Infidel - Aborted Islam with a hanger wrote:
I have two classes(class A, class main). class main uses a pointer to
class A and class A uses a global pointer to main. My problem is I
keep getting these errors: :(
a.h(12) : error C2027: use of undefined type 'main'
a.h(4) : see declaration of 'main'
a.h(12) : error C2227: left of '->SomeDriver' must point to class/
struct/union/generic type
How do I fix this?
[code snipped] see one of his other posts.

What's wrong with you?
Do you read answers to your posts?
Yes.
Jun 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
66
by: Mantorok Redgormor | last post by:
#include <stdio.h> struct foo { int example; struct bar *ptr; }; int main(void) { struct foo baz; baz.ptr = NULL; /* Undefined behavior? */ return 0;
12
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>>...
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
19
by: Sharath A.V | last post by:
I had an argument with someone on wheather this piece of code can invoke undefined bahaviour. I think it does not invoke any undefined behaviour since there is sufficient memory space of 9...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
22
by: blargg | last post by:
Does ~0 yield undefined behavior? C++03 section 5 paragraph 5 seems to suggest so: The description of unary ~ (C++03 section 5.3.1 paragraph 8): But perhaps "one's complement" means the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.