compiles in g++ and .NET but not on VC6 !!!

J

Julian

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 <iostream>

#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<typename Type>

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 two\n";

}
 
K

Kurt Krueckeberg

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 <iostream>

#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<typename Type>

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 two\n";

}

The stream library, I think, changed from VC6 to .NET. You might try using
<stream.h> on VC6. Just a thought.
 
O

Olivier Azeau

Julian said:
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.
 
J

Julian

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 ??
 
M

Mike Wahler

Julian said:
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 <iostream>

#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<typename Type>

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 two\n";

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
 
E

E. Mark Ping

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.
 
J

Julian

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.
 
J

Julian

Julian said:
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.
 
E

E. Mark Ping

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.
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.

moreover, I installed SP5 for VC6 after I installed .NET 2003. would that
have screwed things up ?

No.
 
J

Julian

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.
 
J

Julian

E. Mark Ping said:
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;'
 
R

red floyd

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top