Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

undeclared identifier

1 view
Skip to first unread message

Mr X

unread,
Feb 17, 2003, 12:31:37 AM2/17/03
to
I get "error: 'http':undeclared identifier" when compiling this
code.//header http.h
#include "stdafx.h"
#include <string>
using namespace std;

class http
{
public:
http();
http(string domain, string path);
};

//source http.cpp
#include "stdafx.h"
#include "http.h"

http::http() { }

http::http(string domain, string path):domain(domain), path(path),
bError(false)
{
}

bool http::getHP() { return true; }

//test program
#include <iostream>
#include "http.h"
#include "stdafx.h"

int main(void)
{
http x;
return 0;
}
If I comment out the http x; line everything compiles\links ok.


Colin Girling

unread,
Feb 17, 2003, 11:48:53 AM2/17/03
to
Is this all the code?
You seem to be initialising variable bError, but have not declared it.


"Mr X online.no>" <laasunde@<remove> wrote in message
news:3e510ecb$1...@news.broadpark.no...

Mr X

unread,
Feb 17, 2003, 12:49:14 AM2/17/03
to
I only included part of the code. I have actually declared bError.
The http class compile and links fine, the problem seems to be once I try to
make object out of the class.


"Colin Girling" <colin.g...@virgin.net> wrote in message
news:lm84a.1227$uz6.1...@newsfep1-win.server.ntli.net...

Andrey Tarasevich

unread,
Feb 17, 2003, 12:54:35 PM2/17/03
to
Mr X
> ...

> //test program
> #include <iostream>
> #include "http.h"
> #include "stdafx.h"
>
> int main(void)
> {
> http x;
> return 0;
> }
> If I comment out the http x; line everything compiles\links ok.
> ...

You seem to be using MSVC++ compiler with pre-compiled headers on and the
pre-compiled header include file has its default name - 'stdafx.h'. In this case
everything that you put in your source file before the pre-compiled header
include directive (#include "stdafx.h") is ignored. That applies to '#include'
directives for 'iostream' and 'http.h'. That's what seems to be the reason for
the error. Rearrange these directives so that 'stdafx.h' is at the top.

If you have any additional questions about this feature of MSVC++ compiler, ask
them in a newsgroup dedicated to MSVC++.

--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

0 new messages