Hi.

Can you explain to me on how to "inherit" (if that's the right word) stuff from a header file, and on how to write one? (A header file)

Like if i wrote this;

class Foo {

int a = 123;

}

in a header, how would i call it?

For example, how would i do this:

Foo(); //Calls the Foo class

Using classes was just an example.

Recommended Answers

All 5 Replies

You would have to include that header before you can use it. For example,

//in foo.h
struct Foo{
 //...
};
//main.cpp
#include <iostream>
#include "foo.h"
int main(){
 Foo f;
}

Ah, crap. Did not get it to work, sorry.

Here is my error:

IntelliSense: PCH warning: cannot find a suitable header stop location. An intellisense PCH file was not generated.

And "my" code is just the "struct foo"

Precompiled Header error?

Try adding the class to the pre-compiled header file.

Also you have to have include guards.

Typically for multi-platform you'll want:

#ifndef SOMEHEADER_H
#define SOMEHEADER_H

struct foo{
   int x,y;
};

#endif

Thanks mate, i appreciate your help.

Oh crap I kind of said that wrong, "adding the class to the pch" no lol.

include the file in the PCH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.