Click here to Skip to main content
15,887,450 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: File move and compare in VC++ 6 MFC dialog based program? Pin
Richard MacCutchan22-Feb-11 23:15
mveRichard MacCutchan22-Feb-11 23:15 
QuestionRe: File move and compare in VC++ 6 MFC dialog based program? Pin
ajj10023-Feb-11 9:27
ajj10023-Feb-11 9:27 
AnswerRe: File move and compare in VC++ 6 MFC dialog based program? Pin
David Crow23-Feb-11 9:30
David Crow23-Feb-11 9:30 
AnswerRe: File move and compare in VC++ 6 MFC dialog based program? Pin
ajj10023-Feb-11 9:31
ajj10023-Feb-11 9:31 
QuestionRe: File move and compare in VC++ 6 MFC dialog based program? Pin
ajj10025-Feb-11 5:59
ajj10025-Feb-11 5:59 
AnswerRe: File move and compare in VC++ 6 MFC dialog based program? Pin
David Crow25-Feb-11 6:20
David Crow25-Feb-11 6:20 
AnswerRe: File move and compare in VC++ 6 MFC dialog based program? Pin
Maximilien22-Feb-11 13:54
Maximilien22-Feb-11 13:54 
Questiontemplates & friends Pin
Joerg Koenig22-Feb-11 3:12
Joerg Koenig22-Feb-11 3:12 
Hello,

I'm currently migrating projects from VC6 to VS10 and encountered
a problem using template classes with friend template functions.
The following example was reduced to the minimum to reproduce
the problem. The code compiles without errors/warnings in VC6:

------------------- 8< --------------------------------
#include <StdAfx.h>    // nothing special inside this header.
#include <string>
using namespace std;

class factory;

class attribute {
    protected:
        attribute(const string & table, const string & column, factory * fac);
        attribute(const attribute & attr);
};


template <typename T, typename P>
class attributeimpl : public attribute {
    friend class attribute * MakeAttribute(
                const string & table,
                const string & column,
                factory * fac,
                T P::* member
            );

    typedef T P::* member_t;

    member_t    m_Value;

    protected:
        attributeimpl(const string & table, const string & column, factory * fac, member_t mem)
            : attribute(table, column, fac)
            , m_Value(mem)
        {
        }

        attributeimpl(const attributeimpl<T,P> & attr);
};


template <typename T, typename P> inline
attribute * MakeAttribute(
        const string & table,
        const string & column,
        factory * fac,
        T P::* member) {
    return    (attribute*)(new attributeimpl<T, P> (table, column, fac, member));
}


#define BindVar(CLASS,MEMBER,TABNAME,COLNAME) \
    MakeAttribute(TABNAME, COLNAME, this, &CLASS::MEMBER)


class factory {
    protected:
        factory();
};


class object {
    protected:
        object();
};


// --------------------------------------------------------------------

class myobj : public object {
    friend class myfac;

    string    m_name;
    string    m_surname;
};


class myfac : public factory {
    attribute * name;
    attribute * surname;

    public:
        myfac();
};


myfac::myfac() {
    name = BindVar(myobj, m_name, "customer", "name");
    vorname = BindVar(myobj, m_surname, "customer", "surname");
}

------------------- 8< --------------------------------


VS10 produces the following errors:


------------------- 8< --------------------------------
1>templ.cpp(44): error C2248: 'attributeimpl<t,p>::attributeimpl' : cannot access protected member declared in class 'attributeimpl<t,p>'
1> with
1> [
1> T=std::string,
1> P=myobj
1> ]
1> templ.cpp(28) : see declaration of 'attributeimpl<t,p>::attributeimpl'
1> with
1> [
1> T=std::string,
1> P=myobj
1> ]
1> templ.cpp(85) : see reference to function template instantiation 'attribute *MakeAttribute<std::string,myobj>(const std::string &,const std::string &,factory *,T myobj::* )' being compiled
1> with
1> [
1> T=std::string
1> ]
1>
1>Build FAILED.
------------------- 8< --------------------------------


AFAIK I don't need to explicitly declare a friend function. The compiler
should take the "friend" declaration to declare the function in the next
outer scope that is not a class (in the example this is the global scope).
But even if I explicitly declare the function "MakeAttribute()" in
the global scope and reference the friend declaration to ::, the compiler
gives me errors. In such a case VS10 says it cannot deduce the template
parameters T and P of "MakeAttribute()".

At this point I'm totally clueless... :-|
So how do I have to declare the friend function?

Jörg
AnswerRe: templates & friends Pin
Michael Dunn22-Feb-11 5:47
sitebuilderMichael Dunn22-Feb-11 5:47 
AnswerRe: templates & friends Pin
CPallini22-Feb-11 9:49
mveCPallini22-Feb-11 9:49 
GeneralRe: templates & friends Pin
Rajesh R Subramanian22-Feb-11 19:51
professionalRajesh R Subramanian22-Feb-11 19:51 
GeneralRe: templates & friends Pin
Joerg Koenig22-Feb-11 21:45
Joerg Koenig22-Feb-11 21:45 
Questionwindowless shockwaveflash control doesn't work properly individually Pin
followait21-Feb-11 22:01
followait21-Feb-11 22:01 
AnswerRe: windowless shockwaveflash control doesn't work properly individually Pin
Ahmed Charfeddine22-Feb-11 0:24
Ahmed Charfeddine22-Feb-11 0:24 
GeneralRe: windowless shockwaveflash control doesn't work properly individually Pin
followait22-Feb-11 14:20
followait22-Feb-11 14:20 
QuestionProblem in Excel Automation. Pin
Le@rner21-Feb-11 21:41
Le@rner21-Feb-11 21:41 
AnswerRe: Problem in Excel Automation. Pin
Niklas L21-Feb-11 22:18
Niklas L21-Feb-11 22:18 
QuestionRichEdit and ITextHost scrollbar Pin
Tangwang21-Feb-11 17:26
Tangwang21-Feb-11 17:26 
QuestionGetting File Path of the Current Program [modified] [SOLVED] Pin
AmbiguousName21-Feb-11 7:09
AmbiguousName21-Feb-11 7:09 
AnswerRe: Getting File Path of the Current Program Pin
Hans Dietrich21-Feb-11 7:19
mentorHans Dietrich21-Feb-11 7:19 
AnswerRe: Getting File Path of the Current Program [modified] [SOLVED] Pin
David Crow21-Feb-11 11:05
David Crow21-Feb-11 11:05 
QuestionStripping new line problem Pin
csrss21-Feb-11 4:26
csrss21-Feb-11 4:26 
AnswerRe: Stripping new line problem Pin
Maximilien21-Feb-11 4:48
Maximilien21-Feb-11 4:48 
GeneralRe: Stripping new line problem Pin
csrss21-Feb-11 4:53
csrss21-Feb-11 4:53 
AnswerRe: Stripping new line problem Pin
csrss21-Feb-11 6:17
csrss21-Feb-11 6:17 

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.