-
Class errors
can someone tell me why VC++ .net won't compile this, but Dev C++ 4 does ?
Code:
#include <iostream>
class clearscreen
{
public:void clear()
{
using namespace std;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
}
};
here is the error from .NET
c:\cpp\Game\RPG Game\Clearscreen.cpp(21): error C2872: 'cout' : ambiguous symbol
it comes up 10 times, for each 'cout'
-
It compiles fine in VC++6 if I add a main() function. Have you ever considered that all those couts and endls could be replaced by:
Code:
for(int i=0; i<100; i++)
{
cout<<endl;
}
-
It compiles with .Net 2003 (VC 7.1).
But 100 times endl is very ugly (endl == '\n' + flush)
Code:
for(int i=0; i<100; i++)
{
cout<< '\n';
}
cout.flush();
-
I ended up making it a function instead of a class
I don't know why .NET won't compile it though *shrugs*
Yeah, in my function I added the loop instead of all the couts :)
I didnt worry about the number of couts in the class, but seeing as its now a function, i didnt want a heap of useless lines added :p
-
It works just fine for me in VS .NET 2002.
It sounds like somewhere, through some other #include, that you are ALSO including the deprecated iostreams. For example, I get exactly those errors if I did:
#include <iostream>
#include <iostream.h>
because it doesn't know the difference between std::cout and the global ::cout; both are now in the global namespace.
I'd wager $50 that somewhere, you #include some header that #includes the deprecated iostreams.
Check your output window (not the task window), I bet you ALSO got a warning:
: warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma deprecated
-
.net enterprise architect compiled it fine
-
Any compiler, VC .NET included, would compile it fine; he has an error in the #includes that aren't shown. His error is that there are two "cout"s declared globally, and the compiler doesn't (and can't) know which to use.
-
You should have using namespace std; right after the #include, not in a function.
-
It's OK to put it in a function; it limits the scope of "using" to just that function (which is often better, especially if you're dragging the entirety of std:: into there).
-