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

Discussion in 'C++' started by Julian, Dec 17, 2004.

  1. Julian

    Julian Guest

    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";

    }
     
    Julian, Dec 17, 2004
    #1
    1. Advertising


  2. > 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.
     
    Kurt Krueckeberg, Dec 17, 2004
    #2
    1. Advertising

  3. Julian wrote:
    > 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.
     
    Olivier Azeau, Dec 17, 2004
    #3
  4. Julian

    Julian Guest

    > 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 ??
     
    Julian, Dec 17, 2004
    #4
  5. Julian

    Mike Wahler Guest

    "Julian" <> wrote in message
    news:cpvoh9$fkc$...
    > 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
     
    Mike Wahler, Dec 18, 2004
    #5
  6. Julian

    E. Mark Ping Guest

    In article <cpvr35$hp6$>, Julian <> wrote:
    > > 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
     
    E. Mark Ping, Dec 18, 2004
    #6
  7. Julian

    Julian Guest

    > 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.
     
    Julian, Dec 20, 2004
    #7
  8. Julian

    Julian Guest

    "Julian" <> wrote in message
    news:cq6srq$569$...
    >> 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.
     
    Julian, Dec 20, 2004
    #8
  9. Julian

    red floyd Guest

    Julian wrote:

    > is SP5 the latest service pack for VC6?
    >


    VS6 is at SP6 level.
     
    red floyd, Dec 20, 2004
    #9
  10. Julian

    E. Mark Ping Guest

    In article <cq6srq$569$>, 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.

    >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.
    --
    Mark Ping
     
    E. Mark Ping, Dec 20, 2004
    #10
  11. Julian

    Julian Guest

    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" <> wrote in message
    news:crFxd.1185$...
    > Julian wrote:
    >
    >> is SP5 the latest service pack for VC6?

    >
    > VS6 is at SP6 level.
     
    Julian, Dec 20, 2004
    #11
  12. Julian

    Julian Guest

    "E. Mark Ping" <> wrote in message
    news:cq7a8q$1jfa$...
    > In article <cq6srq$569$>, 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;'
     
    Julian, Dec 20, 2004
    #12
  13. Julian

    red floyd Guest

    red floyd, Dec 21, 2004
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Doe
    Replies:
    9
    Views:
    351
    lilburne
    Oct 23, 2003
  2. Mitch
    Replies:
    4
    Views:
    580
    Mitch
    Apr 22, 2004
  3. Replies:
    7
    Views:
    332
    P.J. Plauger
    Apr 3, 2006
  4. Eric Lilja
    Replies:
    4
    Views:
    440
    Thierry Miceli
    Sep 2, 2005
  5. Olli Plough
    Replies:
    2
    Views:
    333
    Olli Plough
    Dec 7, 2007
Loading...

Share This Page