template programming error

This is a discussion on template programming error within the C++ Programming forums, part of the General Programming Boards category; Code: 1> main.cpp 1>c:\programme\microsoft visual studio 10.0\vc\include\fstream(1116): error C2248: "std::basic_ios<_Elem,_Traits>::basic_ios": Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios<_Elem,_Traits>-Klasse ...

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138

    template programming error

    Code:
    1>  main.cpp
    1>c:\programme\microsoft visual studio 10.0\vc\include\fstream(1116): error C2248: "std::basic_ios<_Elem,_Traits>::basic_ios": Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios<_Elem,_Traits>-Klasse erfolgte.
    1>          with
    1>          [
    1>              _Elem=char,
    1>              _Traits=std::char_traits<char>
    1>          ]
    1>          c:\programme\microsoft visual studio 10.0\vc\include\ios(176): Siehe Deklaration von 'std::basic_ios<_Elem,_Traits>::basic_ios'
    1>          with
    1>          [
    1>              _Elem=char,
    1>              _Traits=std::char_traits<char>
    1>          ]
    1>          Diese Diagnose trat in der vom Compiler generierten Funktion "std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const std::basic_ofstream<_Elem,_Traits> &)" auf.
    1>          with
    1>          [
    1>              _Elem=char,
    1>              _Traits=std::char_traits<char>
    1>          ]
    This is my build log. I hope you can guess what it says despite being in German. It basically says "No access to private member" in some template instantiation.

    To me this looks as if some ofstream object is copy constructed. It should not be. So I've been looking at all my declarations and function parameters if I've missed a "&" and passed a real object instead of a reference. But I found none.

    I also checked all classes that hold ofstream instances as members but none of them is default copy-constructable, all have an explicit constructors with parameters.

    After about 2 hours of guessing and searching I'm really at a loss how to find this. I don't even have a line number to my code. I just know that somewhere in one of the 20 headerfiles included and include-included in main, there is something wrong.

    Does anyone have any idea how to find this?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    i've seen that before.

    did you include both iostream and fstream?

  3. #3
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by nvoigt View Post
    I also checked all classes that hold ofstream instances as members but none of them is default copy-constructable, all have an explicit constructors with parameters.
    Even so, the compiler will automatically generate a copy constructor if you haven't. If you don't want something to be copy-constructible you must define one in a private or protected context.

    Quote Originally Posted by nvoigt View Post
    I don't even have a line number to my code. I just know that somewhere in one of the 20 headerfiles included and include-included in main, there is something wrong.
    Are you sure there isn't a line number associated with the point of instantiation?

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Try with another compiler? I guess it still hasn't been fixed in VC++ to tell you where in the code the implicit copy constructor is required.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    Even so, the compiler will automatically generate a copy constructor if you haven't.
    Oh, I didn't know this. I thought that defining a constructor will not get me the default constructors. Was this changed recently or did I just work with too many languages and forgot parts of C++?

    Thanks for the help people, I finally found it. I had assumed a std::tr1:bind template would take a reference, but obviously it made (or tried to make) a copy of my object instead.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by nvoigt View Post
    Oh, I didn't know this. I thought that defining a constructor will not get me the default constructors. Was this changed recently or did I just work with too many languages and forgot parts of C++?
    No, it's always worked that way. And yes, I do know what you mean - It's easy to forget or mix up features from various programming languages, especially when you use so many on a regular basis. If I didn't have my reference material I'd be lost!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ template error I think?
    By jcafaro10 in forum C++ Programming
    Replies: 17
    Last Post: 01-14-2009, 09:37 AM
  2. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  3. Template linker error
    By Thantos in forum C++ Programming
    Replies: 11
    Last Post: 04-18-2004, 08:06 PM
  4. IDEA: Template meta-programming
    By Sang-drax in forum Contests Board
    Replies: 1
    Last Post: 07-25-2003, 09:21 PM
  5. class template error
    By CodeMonkey in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 02:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21