Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCopying Variants Pin
softwaremonkey5-Nov-10 23:59
softwaremonkey5-Nov-10 23:59 
AnswerRe: Copying Variants Pin
softwaremonkey6-Nov-10 0:42
softwaremonkey6-Nov-10 0:42 
QuestionRegEnumValue not return the correct values Pin
Arnon A5-Nov-10 12:39
Arnon A5-Nov-10 12:39 
AnswerRe: RegEnumValue not return the correct values Pin
«_Superman_»5-Nov-10 14:41
professional«_Superman_»5-Nov-10 14:41 
AnswerRe: RegEnumValue not return the correct values Pin
krmed6-Nov-10 3:50
krmed6-Nov-10 3:50 
GeneralRe: RegEnumValue not return the correct values Pin
Arnon A7-Nov-10 21:25
Arnon A7-Nov-10 21:25 
QuestionRe: RegEnumValue not return the correct values Pin
David Crow6-Nov-10 17:58
David Crow6-Nov-10 17:58 
QuestionCompiler Error in Template Functions...? [modified] Pin
Joseph Dempsey5-Nov-10 7:41
Joseph Dempsey5-Nov-10 7:41 
I have run into a very strange error today and was wondering if anyone else has seen this. Some digging on google suggests it might be a compiler error. I've seen this on VS2008 and GCC 4.1.2.

I was able to build a test harness to repro the issue. It is below:

<pre>

#include <iostream>

class Cloneable
{
public:
template<class TYPE> TYPE* clone() const { return dynamic_cast< TYPE* > ( clone() ); }
virtual Cloneable* clone() const = 0;
};

// simple template class that defines an interface
// for cloning objects.
class X : public Cloneable
{
public:
X(int _y ) : data(_y) { }
virtual ~X() { /* DO NOTHING */ }
virtual Cloneable* clone() const { return new X(data); }

protected:
X() { /* DO NOTHING */ }
int data;
};

class Y : public X
{
public:
Y(double f, int y) : X(y), dataf(f) { /* DO NOTHING */ }
virtual ~Y() { /* DO NOTHING */ }

virtual Cloneable* clone() const { return new Y(dataf, data); }
protected:
double dataf;
};

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int main(int argc, char* argv[])
{
X* x = new X(1);
X* x1 = x->clone<X>();

Y* y = new Y(2.12, 4);
Y* y1 = y->clone<Y>();

delete y;
delete y1;
delete x;
delete x1;

return 0;
}
</pre>

The clone<TYPE> fails in both cases in the main function. It should cast properly. There seem to be two ways to fix this. If i move the templated function from Cloneable to X & Y it works in both cases. The other is to use clone() in the main function and dyna cast there.

A standard C cast in the templated function also doesn't work. Its like the compiler is erroneously changing the protection level on the function and then gets confused and just dumps out the error.

<pre>
1>Compiling...
1>main.cpp
1>.\main.cpp(40) : error C2275: 'X' : illegal use of this type as an expression
1> .\main.cpp(12) : see declaration of 'X'
1>.\main.cpp(40) : error C2059: syntax error : ')'
1>.\main.cpp(43) : error C2275: 'Y' : illegal use of this type as an expression
1> .\main.cpp(24) : see declaration of 'Y'
1>.\main.cpp(43) : error C2059: syntax error : ')'
</pre>

Anyone seen this work in a different compiler or know of a workaround to make it compile (aside from the ones I mentioned)?

--
Joseph Dempsey
Sr. Software Engineer
joseph_r_dempsey@yahoo.com
<div class="modified">modified on Friday, November 5, 2010 2:18 PM</div>
AnswerRe: Compiler Error in Template Functions...? Pin
«_Superman_»5-Nov-10 7:52
professional«_Superman_»5-Nov-10 7:52 
GeneralRe: Compiler Error in Template Functions...? Pin
Joseph Dempsey5-Nov-10 8:01
Joseph Dempsey5-Nov-10 8:01 
GeneralRe: Compiler Error in Template Functions...? Pin
«_Superman_»5-Nov-10 8:02
professional«_Superman_»5-Nov-10 8:02 
GeneralRe: Compiler Error in Template Functions...? Pin
Joseph Dempsey5-Nov-10 8:17
Joseph Dempsey5-Nov-10 8:17 
GeneralRe: Compiler Error in Template Functions...? Pin
«_Superman_»5-Nov-10 8:56
professional«_Superman_»5-Nov-10 8:56 
GeneralRe: Compiler Error in Template Functions...? Pin
Aescleal5-Nov-10 9:12
Aescleal5-Nov-10 9:12 
AnswerRe: Compiler Error in Template Functions...? [modified] Pin
Aescleal5-Nov-10 9:08
Aescleal5-Nov-10 9:08 
AnswerRe: Compiler Error in Template Functions...? [modified] Pin
Paul Michalik6-Nov-10 1:42
Paul Michalik6-Nov-10 1:42 
QuestionUsing a Message-Only Window to Receive Device Change Notification Messages [modified] Pin
Jim Fell5-Nov-10 5:11
Jim Fell5-Nov-10 5:11 
AnswerRe: Using a Message-Only Window to Receive Device Change Notification Messages Pin
Luc Pattyn5-Nov-10 5:32
sitebuilderLuc Pattyn5-Nov-10 5:32 
GeneralRe: Using a Message-Only Window to Receive Device Change Notification Messages Pin
Jim Fell5-Nov-10 5:41
Jim Fell5-Nov-10 5:41 
GeneralRe: Using a Message-Only Window to Receive Device Change Notification Messages Pin
Luc Pattyn5-Nov-10 5:49
sitebuilderLuc Pattyn5-Nov-10 5:49 
AnswerRe: Using a Message-Only Window to Receive Device Change Notification Messages Pin
Luc Pattyn8-Nov-10 12:17
sitebuilderLuc Pattyn8-Nov-10 12:17 
QuestionWhy IMediaSeeking fails to seek while filter graph is already running? Pin
Chesnokov Yuriy5-Nov-10 2:17
professionalChesnokov Yuriy5-Nov-10 2:17 
QuestionRe: Why IMediaSeeking fails to seek while filter graph is already running? Pin
CPallini5-Nov-10 3:32
mveCPallini5-Nov-10 3:32 
AnswerRe: Why IMediaSeeking fails to seek while filter graph is already running? Pin
Chesnokov Yuriy5-Nov-10 3:55
professionalChesnokov Yuriy5-Nov-10 3:55 
QuestionRe: Why IMediaSeeking fails to seek while filter graph is already running? Pin
CPallini5-Nov-10 4:13
mveCPallini5-Nov-10 4:13 

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.