Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Visual C++ Problem

Reply  
Thread Tools
n1gel's Avatar
Junior Member with 5 posts.
 
Join Date: Sep 2006
Experience: Intermediate
28-Sep-2006, 12:30 PM #1
Visual C++ Problem
Hi

I'm writing an MFC application and I’ve come up against a problem.

I have 2 header files:
Datagram.h
InterfaceDlg.h

Now In Datagram.h I create a struct:

typedef struct _DATAGRAM {
unsigned Summary :1;
unsigned Depth :1;
unsigned Image :1;
unsigned Position :1;
unsigned Attitude :1;
unsigned Clock :1;
unsigned Runtime :1;
unsigned Selection :2;
DepthDGRAM DEP;
PosDGRAM POS;
} DATAGRAM;

And in InterfaceDlg.h I create a vector off variable of this type:

std::vector<DATAGRAM> VDG;

Now I have tried using the include statement (#include "Datagrams.h") this works for every other class where I use a DATAGRAM object but not in the InterfaceDlg.h. I get error messages

error C2065: 'DATAGRAM' : undeclared identifier

Is this because it is a header file? Or because InterfaceDlg.h is for a dialog window?

The only way I have got around this is by replacing the include statement with the whole code from the other header file. This is obviously not what I want to do because I have to keep updating both declarations of the DATAGRAM object if I want to change it and I now have two DATAGRAM classes, which is just sloppy.

Hope this all makes sense and if anyone could help that would be really good

Thanks

Nige
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
28-Sep-2006, 04:29 PM #2
Are you declaring an iterator for the vector in a for() loop and then trying to use the iterator outside the scope of the loop?.

Code:
   for (std::vector<DATAGRAM>::iterator i = v.begin() ; i != v.end(); ++i)
   ;
   --i;   // C2065
Another reason could be that you are not instructing the compiler to recognize the std namespace in InterfaceDlg.h.

Code:
using namespace std;
n1gel's Avatar
Junior Member with 5 posts.
 
Join Date: Sep 2006
Experience: Intermediate
29-Sep-2006, 05:34 AM #3
Smile Thanks for the reply
Hi, Thanks for the reply.

I don't think the problem is with the array as i can't even declare a DATAGRAM variable without the error (error C2501: 'DATAGRAM' : missing storage-class or type specifiers)e.g.

Code:
DATAGRAM Dg;
I have already tried the
Code:
using namespace std;
but i still won't work.

Thanks for the help if you have any other ideas that would be great
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
29-Sep-2006, 11:06 AM #4
I know this is silly - but I just noticed that you say there are 2 header files:

Datagram.h
InterfaceDlg.h

Later you refer to this:

(#include "Datagrams.h")

could the 's' on the end be the issue?
n1gel's Avatar
Junior Member with 5 posts.
 
Join Date: Sep 2006
Experience: Intermediate
29-Sep-2006, 11:20 AM #5
Lightbulb Thanks Again for the Input
Yea i wasn't quite that simple but it was pretty simple.

It was baecause the files weren't stored in the same directory i had to change the include statment to

Code:
#include"..\Datagrams.h"
It annoyed me because i would have noticed if the error message was can't find include file weird.

Thanks for your Input though
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:30 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.