By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

differs in levels of indirection from...

P: n/a
Hi
I've a small problem .. can anyone figure it out?

I am working in VS.NET in C++ with MFC. I have a CWinApp-based class
called CTestHarnessApp. I keep getting the 'differs in levels of
indirection from' error whenever I compile this:

CTestHarnessApp theApp;
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;
pTheApp = &theApp;

(missing storage-class or type specifiers)
('int' differs in levels of indirection from 'CTestHarnessApp *')
('initializing' : cannot convert from 'CTestHarnessApp *__w64 ' to
'int' This conversion requires a reinterpret_cast, a C-style cast or
function-style cast)
But everything is okay when I compile this:

CTestHarnessApp theApp;
CTestHarnessApp* pTheApp = &theApp;
//CTestHarnessApp* pTheApp;
//pTheApp = &theApp;
Me no understand!!!
BOR

Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
blimeyoreilly wrote:
I've a small problem .. can anyone figure it out?

I am working in VS.NET in C++ with MFC. I have a CWinApp-based class
called CTestHarnessApp.
Just to let you know, MFC is not topical here by itself. You should not
presume people here know MFC or care about discussing it. So, next time
if you have MFC-specific question (I am not saying this one is) you
should consider posting to microsoft.public.vc.mfc. Back to your problem.
I keep getting the 'differs in levels of
indirection from' error whenever I compile this:

CTestHarnessApp theApp;
This declares an object, supposedly.
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;
This, supposedly, declares a pointer to an object of the same type.
pTheApp = &theApp;
And here you're just assigning the address of 'theApp' object to a pointer
to an object of the same type. Shouldn't give you any problem.

(missing storage-class or type specifiers)
('int' differs in levels of indirection from 'CTestHarnessApp *')
('initializing' : cannot convert from 'CTestHarnessApp *__w64 ' to
'int' This conversion requires a reinterpret_cast, a C-style cast or
function-style cast)
Well, that suggests that 'pTheApp' is not declared as you claim it is.
Are you sure you spelled everything correctly? Did you copy-and-paste
from your actual program or did you type it in?
But everything is okay when I compile this:

CTestHarnessApp theApp;
CTestHarnessApp* pTheApp = &theApp;
You should always try to put those things in the same declaration
statement to avoid typos:

CTestHarnessApp theApp, *pTheApp = &theApp;
//CTestHarnessApp* pTheApp;
//pTheApp = &theApp;
Me no understand!!!


Methinks there is more to it than you're telling. If I am wrong (and
that is not unheard of), then there is something very screwed up with
the compiler you're using.

V
Jul 23 '05 #2

P: n/a
Hi V,
Okay, just dropped in the MFC ref for some context, but I cannot see
how it really affects the issue here. I cut and pasted the code and
the compiler errors.
I am fairly new to c++, coming from a solid c background. Is there a
need to declare a pointer operator function to the class
CTestHarnessApp ?
BOR

Jul 23 '05 #3

P: n/a
BlimeyOReilly wrote:
Okay, just dropped in the MFC ref for some context, but I cannot see
how it really affects the issue here. I cut and pasted the code and
the compiler errors.
I am fairly new to c++, coming from a solid c background. Is there a
need to declare a pointer operator function to the class
CTestHarnessApp ?


No, there should be no need for that.

There can be a problem with the compiler or with your understanding of
some aspects of platform-specific programming. The error message mentions
the '__w64' thing. If you're building a 64-bit target you should
probably consider declaring your pointer in some platform-specific way
(and I am guessing here):

CTestHarnessApp * __w64 pTheApp;

Consult with your compiler documentation on what the implications are for
pointer types in a 64-bit mode. I remember how much pain 'near' and 'far'
pointers gave the programmers of MS Windows 3.*.

V
Jul 23 '05 #4

P: n/a

"blimeyoreilly" <ma**********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi
I've a small problem .. can anyone figure it out?

I am working in VS.NET in C++ with MFC. I have a CWinApp-based class
called CTestHarnessApp. I keep getting the 'differs in levels of
indirection from' error whenever I compile this:
MFC is not C++. Ask a relevent newsgroup for that proprietary language. Code
that only runs in Windows is off-topic here.

CTestHarnessApp theApp;
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;
pTheApp = &theApp;

(missing storage-class or type specifiers)
('int' differs in levels of indirection from 'CTestHarnessApp *')
('initializing' : cannot convert from 'CTestHarnessApp *__w64 ' to
'int' This conversion requires a reinterpret_cast, a C-style cast or
function-style cast)
Isn't this expected and documented with MFC? Try...

CWnd * p = theApp.m_pMainWnd; // if decade old memrory cells still work

Last but not least, consider switching from MFC to WTL if you are going to
do only Windows. Unfortunately for MS, WTL is not documented which in my
humble opinion is a strategic blunder of infinite proportions. A very big
boo-boo. It outdoes MFC so much so in every respect that the small community
that supports WTL have finally convinced MS to release it as open-source
(unfortunately, MS's ATL is still required to run it which means that you
still have to have VC). Some organisations never learn. What a shame.
http://sourceforge.net/projects/wtl/
http://www.codeproject.com/wtl/

Actually, here is an even better proposal, take a look at wxwindows, a cross
platform GUI that is MFC-like which is quickly growing in popularity (you
can't compete with open source):
http://www.wxwindows.org/


But everything is okay when I compile this:

CTestHarnessApp theApp;
CTestHarnessApp* pTheApp = &theApp;
//CTestHarnessApp* pTheApp;
//pTheApp = &theApp;
Me no understand!!!
BOR


Jul 23 '05 #5

P: n/a
I've had a look through the whole setup - compiler options and code.
The only ref to 64-bit compilation (not something I was wanting!) was
an option to warn about code that would be incompatible in 64-bit
compilation. (the /Wp64 option). Removing this simply removed the last
of the errors.
Having another think about the whole problem though, there is only
allowed a single CWinApp object - there must be one and one only. I am
guessing that the declaration of the the CTestHarnessApp* was prefixed
with 'const' by the preprocessor, but without an initialisation value
it was a bit lost. This is the only reason I can think of...

Is this because Windows knows I normally only use Linux???

BOR
ps Thanks for the help

Jul 23 '05 #6

P: n/a

"blimeyoreilly" <ma**********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi
I've a small problem .. can anyone figure it out?

I am working in VS.NET in C++ with MFC. I have a CWinApp-based class
called CTestHarnessApp. I keep getting the 'differs in levels of
indirection from' error whenever I compile this:

CTestHarnessApp theApp;
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;
pTheApp = &theApp;

(missing storage-class or type specifiers)
('int' differs in levels of indirection from 'CTestHarnessApp *')
('initializing' : cannot convert from 'CTestHarnessApp *__w64 ' to
'int' This conversion requires a reinterpret_cast, a C-style cast or
function-style cast)
But everything is okay when I compile this:

CTestHarnessApp theApp;
CTestHarnessApp* pTheApp = &theApp;
//CTestHarnessApp* pTheApp;
//pTheApp = &theApp;
Me no understand!!!
BOR


Is this code inside a function? In the first instance, you're declaring a
pointer, and then assigning a value to it. In the second, you're declaring
the pointer and initializing it.

If that code is outside of a function, then the problem is trying to execute
an assignment statement. You can't do that outside a function. The second
case would work because it's not an assignment, it's initialization of a
variable, which *is* allowed outside of a function.

If this is inside a function, then the problem lies elsewhere, most likely
in code we haven't been shown.

-Howard

Jul 23 '05 #7

P: n/a
This _is_ outside a function. It's not something I had really thought
about before, but now it makes sense.
That about wraps it up. Thanks
BOR

Jul 23 '05 #8

P: n/a

"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:r6*******************@newsread1.mlpsca01.us.t o.verio.net...
CTestHarnessApp theApp;


This declares an object, supposedly.
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;


This, supposedly, declares a pointer to an object of the same type.
pTheApp = &theApp;


And here you're just assigning the address of 'theApp' object to a pointer
to an object of the same type. Shouldn't give you any problem.


.... unless the assignment does not occure in the body of some function
(missing storage-class or type specifiers)
('int' differs in levels of indirection from 'CTestHarnessApp *')
('initializing' : cannot convert from 'CTestHarnessApp *__w64 ' to
'int' This conversion requires a reinterpret_cast, a C-style cast or
function-style cast)


Well, that suggests that 'pTheApp' is not declared as you claim it is.
Are you sure you spelled everything correctly? Did you copy-and-paste
from your actual program or did you type it in?


I guess he did copy (or at least type it without any major typos).
But everything is okay when I compile this:

CTestHarnessApp theApp;
CTestHarnessApp* pTheApp = &theApp;


You should always try to put those things in the same declaration
statement to avoid typos:

CTestHarnessApp theApp, *pTheApp = &theApp;


Some people think different about that.
//CTestHarnessApp* pTheApp;
//pTheApp = &theApp;
Me no understand!!!


Methinks there is more to it than you're telling. If I am wrong (and
that is not unheard of), then there is something very screwed up with
the compiler you're using.


You might be wrong, but that does imply that something is wrong with the
compiler (unless your wrote it ;-)

Regards
Heinz
Jul 23 '05 #9

P: n/a
Heinz Ozwirk wrote:
"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:r6*******************@newsread1.mlpsca01.us.t o.verio.net...
CTestHarnessApp theApp;
This declares an object, supposedly.

//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;


This, supposedly, declares a pointer to an object of the same type.

pTheApp = &theApp;


And here you're just assigning the address of 'theApp' object to a pointer
to an object of the same type. Shouldn't give you any problem.

... unless the assignment does not occure in the body of some function


But then the compiler (IMO) should *not* attempt to declare 'pTheApp'
/again/ as an 'int' and give a more sensible error message, don't you
agree?
[...]

You should always try to put those things in the same declaration
statement to avoid typos:

CTestHarnessApp theApp, *pTheApp = &theApp;

Some people think different about that.


There is probably another way to *avoid typos*, but I can't think of any
at the moment, except typedefing 'CTestHarnessApp' to something shorter
(and significantly shorter).

V
Jul 23 '05 #10

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:mi*******************@newsread1.mlpsca01.us.t o.verio.net...
Heinz Ozwirk wrote:
"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:r6*******************@newsread1.mlpsca01.us.t o.verio.net...
CTestHarnessApp theApp;

This declares an object, supposedly.
//CTestHarnessApp* pTheApp = &theApp;
CTestHarnessApp* pTheApp;

This, supposedly, declares a pointer to an object of the same type.
pTheApp = &theApp;

And here you're just assigning the address of 'theApp' object to a
pointer
to an object of the same type. Shouldn't give you any problem.

... unless the assignment does not occure in the body of some function


But then the compiler (IMO) should *not* attempt to declare 'pTheApp'
/again/ as an 'int' and give a more sensible error message, don't you
agree?


I agree.

I had this problem before, and the VC++ error message was no help at all!
If I recall, CodeWarrior does something similar, but first precedes the
error with another one about "implicit int" being deprecated. One learns to
recognize such errors eventually, but it would be nice to have error
messages that actually tell you the error!

Assuming an int probably helps the parser continue, and then it's just a
matter of trying to describe the error state correctly. That requires a bit
of intelligence, something that can be difficult to add into a
state-machine-based compiler. Now, no comments about the ability of M$ to
add intelligence to anything, please! :-)

-Howard


Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.