473,387 Members | 1,575 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,387 software developers and data experts.

Compile error C4430 with Visual C++ 2005

Hi,
I am working on a legacy code. Following is a line of the code which
complies with Visual C++.NET 2003 but not with Visual C++ 2005:

for ( int i = 0; i < (const)(X.size()); i++ ) {}// X is an object such as a
standard Vector

Compile error with Visual C++ 2005:
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Compiler expect (const int) not (const). My question is why do we need
(const) in the for loop? I am not sure of its purpose. Any explanation of
the problem and possible solutions?

Thanks for your help.

John

Dec 20 '05 #1
3 31158
John wrote:
Hi,
I am working on a legacy code. Following is a line of the code which
complies with Visual C++.NET 2003 but not with Visual C++ 2005:

for ( int i = 0; i < (const)(X.size()); i++ ) {}// X is an object
such as a standard Vector

Compile error with Visual C++ 2005:
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Compiler expect (const int) not (const). My question is why do we need
(const) in the for loop? I am not sure of its purpose. Any
explanation of the problem and possible solutions?


(const) is both meanningless and illegal - take it out, or change it to
(const int), which would be legal but pointless.

-cd
Dec 20 '05 #2
John wrote:
Hi,
I am working on a legacy code. Following is a line of the code which
complies with Visual C++.NET 2003 but not with Visual C++ 2005:

for ( int i = 0; i < (const)(X.size()); i++ ) {}// X is an object such as a
standard Vector

Compile error with Visual C++ 2005:
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Compiler expect (const int) not (const). My question is why do we need
(const) in the for loop? I am not sure of its purpose. Any explanation of
the problem and possible solutions?

Thanks for your help.

John

John:

It is possible that (const) could implicitly mean (const int), but IMHO
"implicit int" was always one of the craziest things in C, and it has (I
think) long been deprecated in C++. Maybe now it is illegal. Get rid of it!

The real problem here is that std::vector::size() is a size_t, which is
unsigned (and 64 bits on 64-bit systems). Therefore to compile without
warnings you need the cast:

for ( int i = 0; i < (int)X.size(); i++ )

But really better is

for ( size_t i = 0; i < X.size(); i++ )

HTH,

David Wilkinson


Dec 20 '05 #3
The original source of "(const)" was probably over-zealous const-correctness.

You are correct, for(int i... doesn't make much sense (but not uncommon)
when you're iterating unsigned values. I would agree that using
for(size_t... is better than the original.

http://www.peterRitchie.com/

"David Wilkinson" wrote:
John wrote:
Hi,
I am working on a legacy code. Following is a line of the code which
complies with Visual C++.NET 2003 but not with Visual C++ 2005:

for ( int i = 0; i < (const)(X.size()); i++ ) {}// X is an object such as a
standard Vector

Compile error with Visual C++ 2005:
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Compiler expect (const int) not (const). My question is why do we need
(const) in the for loop? I am not sure of its purpose. Any explanation of
the problem and possible solutions?

Thanks for your help.

John

John:

It is possible that (const) could implicitly mean (const int), but IMHO
"implicit int" was always one of the craziest things in C, and it has (I
think) long been deprecated in C++. Maybe now it is illegal. Get rid of it!

The real problem here is that std::vector::size() is a size_t, which is
unsigned (and 64 bits on 64-bit systems). Therefore to compile without
warnings you need the cast:

for ( int i = 0; i < (int)X.size(); i++ )

But really better is

for ( size_t i = 0; i < X.size(); i++ )


Dec 21 '05 #4

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

Similar topics

0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
5
by: DFB | last post by:
I am the author of the ZLibNetWrapper project on SourceForge (located at zlibnetwrapper.sf.net). This project is a simple mixed-mode .NET wrapper around the ZLib compression library. The ZLib...
2
by: darko | last post by:
ok, i'm just starting out, with c++ and i downloaded some wideos, i'm working on VS.NET 2005, and hthe first script is helloworld #include <iostream> main() { std::cout << "Hello World"; }...
1
by: Silena | last post by:
Hello I am programming in VC++, VS 2005. The program worked fine, but now I have this error. Previously were several errors like this, I did a reinstalation of SDK, DirectShow, OpenCV and VS2005,...
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
0
by: yyuan168a | last post by:
I'm upgrading a VS2003 project to VS2005 but got bunch of C2039 errors in xutility.h file during compiling: :\Program Files\Microsoft Visual Studio 8\VC\include\xutility(610) : error C2039:...
2
by: LifeStory via DotNetMonster.com | last post by:
Hi all, Currently I am working in Visual C++ using .Net Studio 2005, I have defined a vector of integers in an .h file (class definition), after compilation the following error appears: Error...
1
by: pra1983 | last post by:
can any one can help i am getting an error saying "missing type specifier - int assumed in line 332" but my line of that part are.... 332: getchar(); 333: getchar(); 334: for( i=0 ;...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.