473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiplication instead of pointer declaration

Hi,

I have the following problem:

MyClass.h
---------------

class MyClass {};

This class is included somewhere in another header file:

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;
}

Unfortunately, this does not seem to work. I'm using Visual Studio
2005 and it provides the following error:

error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Obviously, VS does not recognize the type properly, but I can't see
where the problem is.

Some more facts about the project: It's a COM DLL for MS Windows using
ATL, precompiled headers are turned on.

Any solution or help to track down the problem is welcome :)

Thanks,

Stefan Weber

May 2 '07 #1
10 1597
* Stefan Weber:
Hi,

I have the following problem:

MyClass.h
---------------

class MyClass {};
Missing include guards.

This class is included somewhere in another header file:

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;
}
Missing semicolon.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 2 '07 #2
Missing include guards.
>
[...]

Missing semicolon.
Now, it looks like that:

MyClass.h
---------------

#ifndef __MyClass_h__
#define __MyClass_h__

class MyClass {};

#endif

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;

} ;

However, the problem remains.

May 2 '07 #3
Stefan Weber wrote:
>Missing include guards.

[...]

Missing semicolon.

Now, it looks like that:

MyClass.h
---------------

#ifndef __MyClass_h__
#define __MyClass_h__

class MyClass {};

#endif

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;

} ;

However, the problem remains.
Of course, the problems were not related with what you are
experiencing... from the two files you shown everything seems ok, is it
possible that the problem is related to some other header?

Zeppe
May 2 '07 #4
* Stefan Weber:
>Missing include guards.

[...]

Missing semicolon.

Now, it looks like that:

MyClass.h
---------------

#ifndef __MyClass_h__
#define __MyClass_h__

class MyClass {};

#endif

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;

} ;

However, the problem remains.
The problem is not with the code, which apart from the name
__MyClass_h__[1] is OK.

The problem is a misleading diagnostic, combined with something, e.g.
picking up the wrong the include file, that means you don't have a
declaration or definition of MyClass in sight in the main program.

Just get used to misleading diagnostics... And check what "MyClass.h"
file is actually included. Perhaps you have the main program and the
"MyClass.h" file in different folders, with an old copy of "MyClass.h"
in the same folder as the main program?

Hth.,

- Alf
[1] "__" is reserved for the implementation, which means the name is
technically invalid (also, "_" followed by uppercase is reserved), and
macro names should by convention be all uppercase.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 2 '07 #5
On 2 May, 11:13, Stefan Weber <stefan.we...@gmail.comwrote:
Missing include guards.
[...]
Missing semicolon.

Now, it looks like that:

MyClass.h
---------------

#ifndef __MyClass_h__
#define __MyClass_h__
That's not a valid name for an include guard. You aren't allowed to
use double underscores (there are restrictions on leading single
underscores too).

class MyClass {};

#endif

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;

} ;

However, the problem remains.
Simplifying slightly, if I put the following, as a single translation
unit (i.e. not a separate header and source file) into Comeau online,
it compiles OK

class MyClass {};

class Foo {
MyClass* bar;
} ;

Now, changing to VC++ 2005, I put your separate MyClass.h and Foo.h
into a brand new project (<OTyou say you are using VC++ 2005 - I set
up a brand new, empty, console program, with precompiled headers off </
OT>) and created a cpp file containing simply

#include "Foo.h"
int main() {}

the whole program builds OK. Are you sure there is no other code
involved in your program anywhere?

Note that if you find that changing your project setup in any way
makes the problem go away, the best people to ask about understanding
that will be in a Visual C++ group.

Gavin Deane

May 2 '07 #6
On May 2, 2:59 am, Stefan Weber <stefan.we...@gmail.comwrote:
Hi,

I have the following problem:

MyClass.h
---------------

class MyClass {};

This class is included somewhere in another header file:

Foo.h
--------

#include "MyClass.h"

class Foo {
MyClass* bar;

}

Unfortunately, this does not seem to work. I'm using Visual Studio
2005 and it provides the following error:
Lose the #include directive and use a forward declaration instead:

class MyClass;

class Foo {
MyClass * bar;
};

Greg

May 2 '07 #7
Thanks a lot for all your answers. I could not find the error yet, but
I decided to start a new Visual Studio Project and will copy
everything step by step from the old project (luckily, the project is
still very small...). Now it works, but I'd rather understand why
there were problems before, so I'm still searching.

Anyway, can someone explain to me what the problem of a multiple
include could be? I mean, I'm sure that I included the header file
with the class in question. Is there a way that this class will be
undeclared when something with the header files is messed up?

Thanks,

Stefan

May 2 '07 #8
On 2 May, 14:51, Stefan Weber <stefan.we...@gmail.comwrote:
Anyway, can someone explain to me what the problem of a multiple
include could be? I mean, I'm sure that I included the header file
with the class in question. Is there a way that this class will be
undeclared when something with the header files is messed up?
Unless I've missed it, the answer to this one isn't in the FAQ,
although the question is at least as frequently asked as others that
are in the FAQ. But the next best thing is Google, which found:

http://en.wikipedia.org/wiki/Include_guard

Gavin Deane

May 2 '07 #9
Le 02.05.2007 15:51, Stefan Weber a écrit :
Thanks a lot for all your answers. I could not find the error yet, but
I decided to start a new Visual Studio Project and will copy
everything step by step from the old project (luckily, the project is
still very small...). Now it works, but I'd rather understand why
there were problems before, so I'm still searching.
Maybe some hard-to-see typo; kind of like this one:

class SmallObject;

class Box
{
Small0bject *p;
};

--
___________
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Pour bien répondre avec Google, ne pas cliquer
-'(__) « Répondre », mais « Afficher les options »,
_/___(_) puis cliquer « Répondre » (parmi les options).
May 2 '07 #10
Stefan Weber wrote:
Hi,

I have the following problem:
Post a COMPLETE MINIMAL program that demonstrates the problem. Often in
creating the minimal program, the problem will reveal itself.


Brian
May 2 '07 #11

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

Similar topics

11
2511
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same...
110
9812
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
87
11132
by: Vijay Kumar R Zanvar | last post by:
Hi, Why multiplication of pointers is not allowed? Till now I only know this, but not the reason why! PS: As a rule, I searched the FAQ, but could not find an answer. -- Vijay Kumar R...
7
374
by: Joona I Palaste | last post by:
Why is the standard C type for file handles FILE* instead of FILE? AFAIK the type FILE is a pre-defined typedef for some other type anyway. So why not make it instead a typedef for a *pointer* to...
7
8636
by: Michael Birkmose | last post by:
Hi everyone!, Are pointers to incomplete types allowed in ANSI C? I can see that pointer arithmic on pointers to incomple types is impossible, however there are situations where it can be...
3
2291
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
3
1568
by: xhungab | last post by:
Hello, If the function det_Z(), is of this type : complexZ det_Z(double **A); Can I write : do {
5
5270
by: scan87 | last post by:
Can somebody please help me with the following problem. I need to submit the problem on Monday. A program is required which could be used to help a child practice their multiplication tables. The...
3
3863
by: crazygrey | last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but it is important to me. I'm implementing a simple code to find the forward kinematics of a robot: #include "stdafx.h"...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
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,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.