Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov5-Sep-20 4:32
Victor Nijegorodov5-Sep-20 4:32 
QuestionHi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
vinay10829-Aug-20 17:54
vinay10829-Aug-20 17:54 
AnswerRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
Greg Utas30-Aug-20 2:06
professionalGreg Utas30-Aug-20 2:06 
GeneralRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
vinay10830-Aug-20 7:01
vinay10830-Aug-20 7:01 
GeneralRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
Greg Utas30-Aug-20 7:06
professionalGreg Utas30-Aug-20 7:06 
AnswerRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
Mircea Neacsu30-Aug-20 2:07
Mircea Neacsu30-Aug-20 2:07 
GeneralRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
vinay10830-Aug-20 7:05
vinay10830-Aug-20 7:05 
AnswerRe: Hi I am trying to overload >> operator for custom templated vector class but getting error Undifined Type 'T' Pin
Stefan_Lang31-Aug-20 23:53
Stefan_Lang31-Aug-20 23:53 
When using already existing container types from the STL, just use the container type as template parameter. You can retrieve the element type with the internal type definition value_type like this:

C++
template <class Container>
istream& operator>>(istream& my_istream, Container& v)
{
    typedef typename Container::value_type T; // now you can use T for your element type
    ...


If you define your own container type, you can do it in the same way. You just have to make sure your container type does define value_type:
C++
template <class Element>
class MyContainer {
public:
    typedef Element value_type;
    ...


P.S.:
IIRC STL containers already do have overrides for operator>>. You could save yourself some effort by just overriding this operator for your base type:
C++
template <class T>
istream& operator>>(istream& my_istream, T& value) {
...
It should work just as well as the above solution.

P.P.S.:
As it turns out I was wrong. There are no default implementations of operator>> for containers.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)


modified 1-Sep-20 12:11pm.

QuestionWhy does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
hubblee28-Aug-20 10:38
hubblee28-Aug-20 10:38 
AnswerRe: Why does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
jeron128-Aug-20 13:11
jeron128-Aug-20 13:11 
GeneralRe: Why does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
Richard MacCutchan28-Aug-20 21:07
mveRichard MacCutchan28-Aug-20 21:07 
AnswerRe: Why does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
Mircea Neacsu28-Aug-20 15:50
Mircea Neacsu28-Aug-20 15:50 
GeneralRe: Why does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
Richard MacCutchan28-Aug-20 21:07
mveRichard MacCutchan28-Aug-20 21:07 
AnswerRe: Why does a letter disappear when I'm writing the following (the problem is the underlined code.) Pin
Richard MacCutchan28-Aug-20 21:06
mveRichard MacCutchan28-Aug-20 21:06 
QuestionProgramming.. Backtracking. Pin
vafoqome26-Aug-20 6:20
vafoqome26-Aug-20 6:20 
AnswerRe: Programming.. Backtracking. Pin
jeron126-Aug-20 6:22
jeron126-Aug-20 6:22 
QuestionRe: Programming.. Backtracking. Pin
Richard MacCutchan26-Aug-20 21:39
mveRichard MacCutchan26-Aug-20 21:39 
AnswerRe: Programming.. Backtracking. Pin
Stefan_Lang28-Aug-20 5:23
Stefan_Lang28-Aug-20 5:23 
AnswerRe: Programming.. Backtracking. Pin
Patrice T28-Aug-20 14:24
mvePatrice T28-Aug-20 14:24 
QuestionI want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Member 1487268117-Aug-20 23:12
Member 1487268117-Aug-20 23:12 
AnswerRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Randor 19-Aug-20 18:29
professional Randor 19-Aug-20 18:29 
GeneralRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Member 1487268119-Aug-20 18:55
Member 1487268119-Aug-20 18:55 
GeneralRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Randor 19-Aug-20 19:12
professional Randor 19-Aug-20 19:12 
GeneralRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Member 1487268119-Aug-20 20:07
Member 1487268119-Aug-20 20:07 
GeneralRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Randor 19-Aug-20 21:10
professional Randor 19-Aug-20 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.