• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# WTF is wrong with my VC?

This topic is 5877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I seem to have a major problem with my visual c++. I have a class which contains several functions. For arguments sake lets use this simple class:
  class testClass { // Construction public: testClass(){} ~testClass(){} // Some Functions public: int GetData() { return m_Data; } void DoStuff(); // Does some stuff // Some data protected: int m_Data; }; 
The problem is strange. I take the class (not this one, a much more complicated one) and go to use it.... include its header, yada yada yada.... do something like this:
  testClass aTester; aTester.DoStuff(); 
perfectly leagal right? OF COURSE IT IS! Well my compiler doesn''t like it! It gives me this error: error C2228: left of ''.Resize'' must have class/struct/union type where in my example Resize would be the DoStuff function. Ok so if thats not weird, copy paste the class into a different project, AND IT WORKS!! So i figure, hey maybe my project file is messed up. I back up the headers and source files. I delete the project folder, recreate and readd the files... SAME ERROR!! waht the heck is going on!!?!?! - SniperBoB

#### Share this post

##### Share on other sites
Advertisement
Look for misspellings and misplaced semicolons/braces on preceding lines. They confuse the parser.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

#### Share this post

##### Share on other sites
quote:
Ok so if thats not weird, copy paste the class into a different project, AND IT WORKS!!

I can''t figure it out. I''m about 10 seconds away from switching to Codewarrior, and 10 minutes away from switching to linux :-)

-SniperBoB

#### Share this post

##### Share on other sites
quote:
Original post by SnprBoB86
I can''t figure it out. I''m about 10 seconds away from switching to Codewarrior, and 10 minutes away from switching to linux :-)

Not that that would help your situation at all. If you''re going to claim to switch software, you may want to do it for valid reasons . I''m very sure it''s something you''ve done wrong .

[Resist Windows XP''s Invasive Production Activation Technology!]

#### Share this post

##### Share on other sites
That was completely unrelated, I am having other Microsoft-Related problems.

but....

DOES ANYONE HAVE ANY CLUE WHAT THE PROBLEM COULD BE?!?

#### Share this post

##### Share on other sites
i don't use VC++ but your error message looks like a variation of one that i have seen before (no promises)... are you sure you are doing this:
testClass aTester;aTester.DoStuff();

and not this:
testClass* aTester = new testClass();aTester.DoStuff();

?
that error occurs when you use . rather than -> (you need this arrow thing when accessing members of a class pointer, instead of the dot for accessing members of a class declared the regular way)...
you'd have to do it this way:
testClass* aTester = new testClass();aTester->DoStuff();

if not then sorry, i dunno... but i figured i'd give it a shot!

--- krez (krezisback@aol.com)

Edited by - krez on January 15, 2002 8:41:32 PM

#### Share this post

##### Share on other sites
quote:

Ok so if thats not weird, copy paste the class into a different project, AND IT WORKS!! So i figure, hey maybe my project file is messed up. I back up the headers and source files. I delete the project folder, recreate and readd the files... SAME ERROR!!

This tells me that the way in which you're using the objects in the second project is not exactly the same as the way you're using it where you get the error. Like someone said, that error usually comes when you try to use .Method() where you really have a pointer, or ->Method() where you really have an object.

The project file is simply a make file. What you're getting is a parsing error, so the project is already compiling the correct code; there are no problems with the project file. If you're using precompiled headers there is a chance that the header hasn't recompiled and should, but if a rebuild-all doesn't do it then the error is in your code.

PS: blaming MS for everything may make you look cool to newbies, but it also makes you look like a newbie to old timers.

Edited by - Stoffel on January 15, 2002 8:51:58 PM

#### Share this post

##### Share on other sites
quote:
Original post by Stoffel
PS: blaming MS for everything may make you look cool to newbies, but it also makes you look like a newbie to old timers.

Classic. Let''s print some T-Shirts.

#### Share this post

##### Share on other sites
its absolutly not a pointer related problem... all instances are actual objects, but regaurdless i have tryed the -> also..... see the members aren''t even appearing in the class view

#### Share this post

##### Share on other sites
OK, thinking it over and testing a few things out.... I am 100% positive it is a bug. If I create a class with all directly inlined functions in some projects it seems to work perfectly, but in others the above stated error occurs. Also in the faulting projects/builds/whatever the functions guilty of this error do not appear in the class view. I believe regaurdless of what the "old timers" say I believe it is most definitly Microsoft''s fault because on closer examination it seems to only happen to templated classes. We all know how badly MSVC++ cokes on templates.

So basicly what I''m trying to say is FLAME LESS.... HELP MORE. This is why I was reluctant to post my plee for help on a message board. Because almost every single thread turns into a breeding ground for little bastards who insist on insulting everyone with a question. I would like to publicly thank everyone who uses the fourms properly (specificly to you Oluseyi and krez in this thread).

Anyone else have any ideas on my problem?

SniperBoB

#### Share this post

##### Share on other sites
have you included (#include) you header
into your main source area?
Sometime we forget that stuff...

[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing."
- Wernher Von Braun (1912-1977)

#### Share this post

##### Share on other sites
Maybe if you posted your actual code rather than whining about Microsoft!

#### Share this post

##### Share on other sites
quote:
Original post by SnprBoB86
We all know how badly MSVC++ cokes on templates.

We sure do. But up until now, there was no indication that you were using templates.

#### Share this post

##### Share on other sites
the includes are fine....

anon poster... shut the hell up, thank you

and i just relized today that they were all templated, i have three classes that are offenders of this. One was originally not templated, so I forgot I had changed it to be templated.

#### Share this post

##### Share on other sites
quote:
Original post by SnprBoB86
I am 100% positive it is a bug... I believe regaurdless of what the "old timers" say I believe it is most definitly Microsoft''s fault because on closer examination it seems to only happen to templated classes.

If I may [mis?]quote Oluseyi: "Regardless of how much you think you know, it is not the compiler''s fault; it is yours." Well, that''s not really a quote, but it is the gist of what he has said before.
Just so you can see for yourself, try it with a different compiler.

#### Share this post

##### Share on other sites
quote:
Original post by SnprBoB86
the includes are fine....

anon poster... shut the hell up, thank you

and i just relized today that they were all templated, i have three classes that are offenders of this. One was originally not templated, so I forgot I had changed it to be templated.

Snappy attitude. I''m unimpressed.

As far as I''m concerned you''ve fucked up, you don''t know where, how or why and you''re too stubborn to accept it. I never have that problem, which counters your own evidence (and therefore we can''t blame it on Microsoft). As I said earlier, look for misplaced statement delimiters (hint: select all text in the file and hit Alt-F8 to autoformat. If you see anything out of place...)

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

#### Share this post

##### Share on other sites
I have been looking for codewarrior all night long!

:-)

Anyone want to give me a "learners" copy??

#### Share this post

##### Share on other sites
Frankly Bob, people like you were not made to be programmers. I was going to try and help, but as its likely you will ignore my advice just like you ignored everyone elses, I wont bother.

#### Share this post

##### Share on other sites
If you don''t post your code, we can''t help.

1. If you are so 100% certain there''s a bug, get the lastest VC++ Service Pack. If that doesn''t solve your problem, it''s not a bug. I''ve been using VC++ professionally for well over 2 years now, and never have I had to blame the compiler for anything that wasn''t documented.

2. If you refuse to post your ACTUAL code, we can''t help. The error you mentioned is very typical of making a typo in the code where you use the class. It''s also the wrong error for us to make any kinds of statements about what''s going wrong - check the NEXT error that the parser gives you, which is most likely something along the lines of "Unknown class or type testClass".

3. Do NOT include ANYTHING before including stdafx. Ever.

4. Reiterating 2. Post your actual code. And prepare to be embarrased by a really silly error you overlooked, because 99% of the time that''s what has happened (and it happens even if you''ve been programming professionally for 2 years, so you better get used to it )

People might not remember what you said, or what you did, but they will always remember how you made them feel.

#### Share this post

##### Share on other sites
Ok...I think everybody glossed over his original post:

quote:
Original post by SnprBoB86 perfectly leagal right? OF COURSE IT IS! Well my compiler doesn't like it! It gives me this error:

error C2228: left of '.Resize' must have class/struct/union type

where in my example Resize would be the DoStuff function.

Obviously the error is not in the code that you showed us, because I don't see a .Resize() function anywhere. It's obviously (and I mean obviously) located some where else in the code. How about showing us the actual code, and we'd be able to see how your declaring and using whatever class Resize() is in??

-Pac

"The thing I like about friends in my classes is that they can't access my private members directly."
"When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."

Edited by - Pactuul on January 16, 2002 5:25:12 AM

Edited by - Pactuul on January 16, 2002 5:26:14 AM

#### Share this post

##### Share on other sites
If you are using templates, make sure that you have the actual body of the funtion in the header file rather than in a seperate cpp file. Or include the c file at the bottom of the header file. Or declare an instance of each templated type somewhere in the header file.

Or simply post your code.

I removed calling you a tit, since i thought it was a bit harsh
[/edit]

Edited by - Tessellator on January 16, 2002 5:36:35 AM

#### Share this post

##### Share on other sites
quote:
Original post by SnprBoB86
We all know how badly MSVC++ cokes on templates.

i don''t seems like a user problem than a software problem

-Pactuul

"The thing I like about friends in my classes is that they can''t access my private members directly."
"When listening to some one tell about their problem (whether it''s code or not), don''t listen to what went right or wrong, but what they assumed....."

#### Share this post

##### Share on other sites
quote:

3. Do NOT include ANYTHING before including stdafx. Ever.

Sorry if this is offtopic but what is stdafx? Ive seen in sourcecode before but never needed to use it.

Jeff D

Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton

#### Share this post

##### Share on other sites
It''s a header file needed when you''re using precompiled headers. It complains if you don''t include it, but it also has a nasty habit of un-defining all the macro''s you defined BEFORE including it, and possibly with classes as well.
Bottom line:
first include in your source file should be stdafx.h if you need it.

People might not remember what you said, or what you did, but they will always remember how you made them feel.

#### Share this post

##### Share on other sites
It is always someone elses fault, or the compilers fault, or the IDEs fault, or Microsofts fault, or your grandmas fault..........never your own is it ?

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

#### Share this post

##### Share on other sites

This topic is 5877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

This topic is now closed to further replies.

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 9
• 10
• 12
• 10
• 10
• Advertisement