Click here to Skip to main content
15,889,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMultiple dynamically created Spin Button Controls Pin
gokings27-Nov-13 11:37
gokings27-Nov-13 11:37 
AnswerRe: Multiple dynamically created Spin Button Controls Pin
Richard MacCutchan27-Nov-13 22:15
mveRichard MacCutchan27-Nov-13 22:15 
GeneralRe: Multiple dynamically created Spin Button Controls Pin
gokings28-Nov-13 7:08
gokings28-Nov-13 7:08 
QuestionCJBK_View::OnDraw(CDC* p_DC) Pin
BarryPearlman27-Nov-13 10:50
BarryPearlman27-Nov-13 10:50 
AnswerRe: CJBK_View::OnDraw(CDC* p_DC) Pin
Richard MacCutchan27-Nov-13 22:10
mveRichard MacCutchan27-Nov-13 22:10 
AnswerRe: CJBK_View::OnDraw(CDC* p_DC) Pin
BarryPearlman28-Nov-13 10:28
BarryPearlman28-Nov-13 10:28 
GeneralRe: CJBK_View::OnDraw(CDC* p_DC) Pin
Richard MacCutchan28-Nov-13 22:41
mveRichard MacCutchan28-Nov-13 22:41 
QuestionFriend Operators of Template Classes Pin
Skippums27-Nov-13 7:00
Skippums27-Nov-13 7:00 
First, the problem: I have a template class (Foo) that will have a friend operator + that takes type T as the first parameter, and type Foo<T> as the second. The forward declaration is:
C++
template<class T> struct Foo;
template<class T> Foo<T> operator +(T const a1, Foo<T> const &a2);


I am using Visual Studio 2010 Pro. Doing a search resulted in the following two links that I thought would be helpful:

http://www.parashift.com/c++-faq-lite/template-friends.html[^]
http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/index.jsp?topic=/com.ibm.vacpp7l.doc/language/ref/clrc16friends_and_templates.htm[^]

These recommendations lead me to try the following after the above forward declaration:
C++
template<class T = double>
struct Foo {
private:
    T m_Data;
    // The following all result in the specified error when attempting to use this friend
    // LNK2019: unresolved external symbol "struct Foo<double> __cdecl operator+(
    //          double, struct Foo<double> const &)" ...
    friend Foo<T> operator +(T const a1, Foo<T> const &a2);
    // C2143: syntax error : missing ';' before '<'
    // C2460: '+' : uses 'Foo<T>', which is being defined
    // C2433: '+' : 'friend' not permitted on data declarations
    // C2365: 'operator +' : redefinition; previous definition was 'function'
    // C2238: unexpected token(s) preceding ';'
    friend Foo<T> operator + <>(T const a1, Foo<T> const &a2);
    // Same errors as above (C2143, C2460, C2433, C2365, C2238)
    friend Foo<T> operator + <T>(T const a1, Foo<T> const &a2);
    // C3637: 'operator +' : a friend function definition cannot be a specialization of a function template
    // C3412: 'operator +' : cannot specialize template in current scope
    template<>
    friend Foo<T> operator +(T const a1, Foo<T> const &a2);

public:
    Foo operator +(T const addend);
};

template<class T>
Foo<T> operator +(T const a1, Foo<T> const &a2) {
    return (a2 + a1);
}

Is there some way to accomplish this? It works if I define (implement) the method within the class declaration, but I prefer to define the method body with the other method declarations (in an included cpp file) for consitency and cleanliness. Thanks,
Sounds like somebody's got a case of the Mondays

-Jeff

AnswerRe: Friend Operators of Template Classes Pin
Freak3027-Nov-13 22:05
Freak3027-Nov-13 22:05 
GeneralRe: Friend Operators of Template Classes Pin
Skippums29-Nov-13 14:35
Skippums29-Nov-13 14:35 
AnswerRe: Friend Operators of Template Classes Pin
Stefan_Lang27-Nov-13 22:40
Stefan_Lang27-Nov-13 22:40 
GeneralRe: Friend Operators of Template Classes Pin
Skippums29-Nov-13 14:34
Skippums29-Nov-13 14:34 
GeneralRe: Friend Operators of Template Classes Pin
Stefan_Lang2-Dec-13 0:17
Stefan_Lang2-Dec-13 0:17 
QuestionFindFirstFile not working Pin
sachanratnesh26-Nov-13 18:58
sachanratnesh26-Nov-13 18:58 
AnswerRe: FindFirstFile not working Pin
Jochen Arndt26-Nov-13 20:59
professionalJochen Arndt26-Nov-13 20:59 
AnswerRe: FindFirstFile not working Pin
Richard MacCutchan26-Nov-13 22:59
mveRichard MacCutchan26-Nov-13 22:59 
AnswerRe: FindFirstFile not working Pin
Gisle Vanem26-Nov-13 23:50
Gisle Vanem26-Nov-13 23:50 
AnswerRe: FindFirstFile not working Pin
Joe Woodbury27-Nov-13 4:21
professionalJoe Woodbury27-Nov-13 4:21 
QuestionRe: FindFirstFile not working Pin
David Crow30-Nov-13 15:00
David Crow30-Nov-13 15:00 
QuestionC++ Plotting utility Pin
kpks26-Nov-13 18:45
kpks26-Nov-13 18:45 
AnswerRe: C++ Plotting utility Pin
Richard Andrew x6427-Nov-13 13:10
professionalRichard Andrew x6427-Nov-13 13:10 
GeneralRe: C++ Plotting utility Pin
kpks27-Nov-13 19:06
kpks27-Nov-13 19:06 
Questionsizeof Operator Pin
Richard Andrew x6426-Nov-13 15:48
professionalRichard Andrew x6426-Nov-13 15:48 
AnswerRe: sizeof Operator Pin
«_Superman_»26-Nov-13 19:00
professional«_Superman_»26-Nov-13 19:00 
GeneralRe: sizeof Operator Pin
Richard Andrew x6427-Nov-13 8:03
professionalRichard Andrew x6427-Nov-13 8:03 

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.