473,568 Members | 2,882 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 1605
* 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...@g mail.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...@g mail.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...@g mail.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

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

Similar topics

11
2518
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 algorithm, when implemented in C or C++. I noticed that the implementation in C is faster by a factor of 2.5 compared to a identical(?)...
110
9818
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 must be an object instead of
87
11158
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 Zanvar
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 that type? For one thing, that would stop people trying to poke around at the insides of a FILE. For another, it could allow for cases where the...
7
8656
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 useful: consider this:
3
2294
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 *, void*))(numeric ? numcmp : strcmp) ); I guess what interests me is the nameless function pointer and then the
3
1577
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
5274
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 program should start by asking the user how many multiplication problems they would like to try, and read this value from the keyboard. Then, the...
3
3870
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" #include<iostream> #include<iomanip> #include<fstream> #include"math.h"
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.