views:

161

answers:

1

i have written the body of the function in the header file and so do not have a source file. when i tried running my project in visual studio .. i got an

error: Cannot open source file: No such file or directory.

How do I make visual studio understand that the definitions of the function are within the header itself?

+3  A: 

You need to create a dummy source.cpp file just containing #include "source.h"

edit - I just tried this - Visual studio will let you do.

test.cpp

#include "test.h"

where test.h

#include "stdio.h"
int main()
{
   printf("hello world");
   return 0;
}

Interesting - but pointless !

Martin Beckett
You do not need to do this. You can inline functions simply by creating them within the header file. There is something else fundamentally wrong here.
wheaties
I'm guessing that this is the only file in his project. VS wont build a project with only headers.
Martin Beckett
You can put all sorts of things in the header file, but unless there's at least one source file, Visual Studio won't compile anything. (BTW, functions aren't inlined by being in the header file, they're automatically inlined by being in the class definition.)
David Thornley