| View previous topic :: View next topic |
| Author |
Message |
Julian Guest
|
Posted: Fri Dec 17, 2004 11:02 pm Post subject: compiles in g++ and .NET but not on VC6 !!! |
|
|
the following code compiles in g++ and .NET but i get the following error
when i compile it in VC6:
error C2667: '<<' : none of 2 overload have a best conversion (in the main
function)
error C2593: 'operator <<' is ambiguous
whats the problem here ??
i'm just shooting in the dark here but is there some setting in vc6 when i
can tell it to compile using ansi standards ?
#include
#include <fstream>
#include <vector>
using namespace std;
class MultiStreamWriter {
private:
vector<ostream *> m_vecWriters;
public:
MultiStreamWriter(void) {
Log.open("log.txt");
}
~MultiStreamWriter(void) {
Log.close();
}
ofstream Log;
template<typename Type>
friend MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter,
const Type &a_typOutput);
};
template
MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter, const Type
&a_typOutput) {
a_mswWriter.Log << a_typOutput;
cout << a_typOutput;
return a_mswWriter;
}
int main(void) {
MultiStreamWriter l_mswWriter;
l_mswWriter << "file one and file twon";
}
|
|
| Back to top |
|
 |
Kurt Krueckeberg Guest
|
Posted: Fri Dec 17, 2004 11:08 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
| Quote: | the following code compiles in g++ and .NET but i get the following error
when i compile it in VC6:
error C2667: '<<' : none of 2 overload have a best conversion (in the main
function)
error C2593: 'operator <<' is ambiguous
whats the problem here ??
i'm just shooting in the dark here but is there some setting in vc6 when i
can tell it to compile using ansi standards ?
#include
#include
#include
using namespace std;
class MultiStreamWriter {
private:
vector
public:
MultiStreamWriter(void) {
Log.open("log.txt");
}
~MultiStreamWriter(void) {
Log.close();
}
ofstream Log;
template<typename Type
friend MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter,
const Type &a_typOutput);
};
template
MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter, const
Type &a_typOutput) {
a_mswWriter.Log << a_typOutput;
cout << a_typOutput;
return a_mswWriter;
}
int main(void) {
MultiStreamWriter l_mswWriter;
l_mswWriter << "file one and file twon";
}
|
The stream library, I think, changed from VC6 to .NET. You might try using
|
|
| Back to top |
|
 |
Olivier Azeau Guest
|
Posted: Fri Dec 17, 2004 11:44 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
Julian wrote:
| Quote: | the following code compiles in g++ and .NET but i get the following error
when i compile it in VC6:
error C2667: '<<' : none of 2 overload have a best conversion (in the main
function)
error C2593: 'operator <<' is ambiguous
whats the problem here ??
i'm just shooting in the dark here but is there some setting in vc6 when i
can tell it to compile using ansi standards ?
|
VC6 is 6 or 7 y.o. so don't expect too much regarding "standards".
My guess is that it cannot perfectly cope with your "template friend"
declaration and it records declaration/definition of operator<< as 2
distinct operators.
|
|
| Back to top |
|
 |
Julian Guest
|
Posted: Fri Dec 17, 2004 11:45 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
| Quote: | The stream library, I think, changed from VC6 to .NET. You might try
using
stream.h> on VC6. Just a thought.
|
it worked !! but i don't understand... there are differences within the
<iostream> between different versions of visual studio ???!!!
aren't the "no .h" headers supposed to follow some common standard ?
so, i guess that means .NET is not backward compatible ? u can't just take
any code that compiles in msvc6.0 and expect it to work in .net ??
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Sat Dec 18, 2004 12:48 am Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
"Julian" <julvar (AT) nospamtamu (DOT) edu> wrote
| Quote: | the following code compiles in g++ and .NET but i get the following error
when i compile it in VC6:
error C2667: '<<' : none of 2 overload have a best conversion (in the main
function)
error C2593: 'operator <<' is ambiguous
whats the problem here ??
i'm just shooting in the dark here but is there some setting in vc6 when i
can tell it to compile using ansi standards ?
#include
#include
#include
using namespace std;
class MultiStreamWriter {
private:
vector
public:
MultiStreamWriter(void) {
Log.open("log.txt");
}
~MultiStreamWriter(void) {
Log.close();
}
ofstream Log;
template
friend MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter,
const Type &a_typOutput);
};
template
MultiStreamWriter & operator << (MultiStreamWriter &a_mswWriter, const
Type
&a_typOutput) {
a_mswWriter.Log << a_typOutput;
cout << a_typOutput;
return a_mswWriter;
}
int main(void) {
MultiStreamWriter l_mswWriter;
l_mswWriter << "file one and file twon";
|
return 0; /* prevent incorrect VC6 diagnostic */
With the minor change above, your code compiles without
errors for me with VC++ v6.0. Do you have the latest
Service Pack installed? (get it from www.msdn.microsoft.com,
you can either download it, or have them ship a CD
for anominal shipping fee)
IMO better yet would be to upgrade to v7.x
I don't have it yet, but it's purported to have
much better standards-conformance.
-Mike
|
|
| Back to top |
|
 |
E. Mark Ping Guest
|
Posted: Sat Dec 18, 2004 1:41 am Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
In article <cpvr35$hp6$1 (AT) news (DOT) tamu.edu>, Julian <julvar (AT) nospamtamu (DOT) edu> wrote:
| Quote: | The stream library, I think, changed from VC6 to .NET. You might try
using
stream.h> on VC6. Just a thought.
it worked !! but i don't understand... there are differences within the
iostream> between different versions of visual studio ???!!!
aren't the "no .h" headers supposed to follow some common standard ?
so, i guess that means .NET is not backward compatible ? u can't just take
any code that compiles in msvc6.0 and expect it to work in .net ??
|
i => I
u => you
Typically only 1 ? or ! is necessary. It's painful to read this, let
alone respond.
That being said, VS6 was released before the C++ standard was
finalized, and hence you shouldn't be surprised that there are some
inconsistencies. VS7.1 (.NET 2003) is very nearly fully conforming to
the standard.
Don't simply switch <iostream.h> and <iostream> without understanding
what it means.
It is quite common for some code tweaking to be necessary when
upgrading a major version of your compiler. With care you can write
code that will compile on VS6, VS7 and VS7.1.
--
Mark Ping
[email]emarkp (AT) soda (DOT) CSUA.Berkeley.EDU[/email]
|
|
| Back to top |
|
 |
Julian Guest
|
Posted: Mon Dec 20, 2004 3:58 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
| Quote: | With the minor change above, your code compiles without
errors for me with VC++ v6.0. Do you have the latest
Service Pack installed? (get it from www.msdn.microsoft.com,
you can either download it, or have them ship a CD
for anominal shipping fee)
IMO better yet would be to upgrade to v7.x
I don't have it yet, but it's purported to have
much better standards-conformance.
-Mike
guess I forgot to include that line when I posted the code but it still |
doesn't compile on my computer.
is SP5 the latest service pack for VC6? I installed that but it made no
difference. is there any other reason why it doesn't compile for me ?
I also have .NET 2003 on the same computer. Is it ok to have both Visual
Studio 6 as well as .NET 2003 on the same computer ?
moreover, I installed SP5 for VC6 after I installed .NET 2003. would that
have screwed things up ?
julian.
|
|
| Back to top |
|
 |
Julian Guest
|
Posted: Mon Dec 20, 2004 4:47 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
"Julian" <julvar (AT) nospamtamu (DOT) edu> wrote
| Quote: | With the minor change above, your code compiles without
errors for me with VC++ v6.0. Do you have the latest
Service Pack installed? (get it from www.msdn.microsoft.com,
you can either download it, or have them ship a CD
for anominal shipping fee)
IMO better yet would be to upgrade to v7.x
I don't have it yet, but it's purported to have
much better standards-conformance.
-Mike
guess I forgot to include that line when I posted the code but it still
doesn't compile on my computer.
is SP5 the latest service pack for VC6? I installed that but it made no
difference. is there any other reason why it doesn't compile for me ?
I also have .NET 2003 on the same computer. Is it ok to have both Visual
Studio 6 as well as .NET 2003 on the same computer ?
moreover, I installed SP5 for VC6 after I installed .NET 2003. would that
have screwed things up ?
julian.
I also tried compiling it with VC6 SP5 on another computer that does not |
have .NET but it still gave the same compile errors.
julian.
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Mon Dec 20, 2004 7:08 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
Julian wrote:
| Quote: | is SP5 the latest service pack for VC6?
|
VS6 is at SP6 level.
|
|
| Back to top |
|
 |
E. Mark Ping Guest
|
Posted: Mon Dec 20, 2004 7:47 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
In article <cq6srq$569$1 (AT) news (DOT) tamu.edu>, Julian <julvar (AT) nospamtamu (DOT) edu> wrote:
| Quote: | guess I forgot to include that line when I posted the code but it still
doesn't compile on my computer.
|
You forgot a line in the middle but left the closing brace? Post the
full code and the actual error messages if you want help.
| Quote: | I also have .NET 2003 on the same computer. Is it ok to have both Visual
Studio 6 as well as .NET 2003 on the same computer ?
|
Yes.
| Quote: | moreover, I installed SP5 for VC6 after I installed .NET 2003. would that
have screwed things up ?
|
No.
--
Mark Ping
[email]emarkp (AT) soda (DOT) CSUA.Berkeley.EDU[/email]
|
|
| Back to top |
|
 |
Julian Guest
|
Posted: Mon Dec 20, 2004 9:11 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
apparently, sp6 doesn't come up in the search results unless you
specifically look for 'sp6'
anyway, I installed sp6 and now it compiles without errors.
thanks,
julian.
"red floyd" <no.spam (AT) here (DOT) dude> wrote
| Quote: | Julian wrote:
is SP5 the latest service pack for VC6?
VS6 is at SP6 level.
|
|
|
| Back to top |
|
 |
Julian Guest
|
Posted: Mon Dec 20, 2004 9:17 pm Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
"E. Mark Ping" <emarkp (AT) soda (DOT) csua.berkeley.edu> wrote
| Quote: | In article <cq6srq$569$1 (AT) news (DOT) tamu.edu>, Julian
wrote:
guess I forgot to include that line when I posted the code but it still
doesn't compile on my computer.
You forgot a line in the middle but left the closing brace? Post the
full code and the actual error messages if you want help.
those were the actual error messages. |
the compiler didn't give any errors for the missing 'return 0;'
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Tue Dec 21, 2004 12:00 am Post subject: Re: compiles in g++ and .NET but not on VC6 !!! |
|
|
Julian wrote:
| Quote: | apparently, sp6 doesn't come up in the search results unless you
specifically look for 'sp6'
anyway, I installed sp6 and now it compiles without errors.
thanks,
julian.
|
You're welcome.
Please don't top-post.
Also, http://msdn.microsoft.com/vstudio click on the "downloads =>
product update" on the left hand side of the screen, gives you this
page: http://msdn.microsoft.com/vstudio/downloads/updates/default.aspx
And VS6SP6 is the second item.
|
|
| Back to top |
|
 |
|