Hello,
I was working on a project when I came to an error that was bothering me. I'm using Visual Studio 2005, and the following code gives me these link errors:
example.h
example.cpp
main.cpp
I want to keep the getVal() method constant in my project, so I use that here.
Now, if I remove the inline keywords, I don't get errors. If I place the class dec and def in main.cpp, I don't get the errors. What is going on here?
I was working on a project when I came to an error that was bothering me. I'm using Visual Studio 2005, and the following code gives me these link errors:
1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall example::getVal(void)const " (?getVal@example@@QBEHXZ) referenced in function _main
1>C:\Documents and Settings\u0095655\My Documents\Visual Studio 2005\Projects\vaschform\Debug\vaschform.exe : fatal error LNK1120: 1 unresolved externals
example.h
#pragma once
class example
{
public:
example();
inline int getVal() const;
private:
int val;
};
example.cpp
#include "example.h"
example::example()
{
val = 10;
}
inline int example::getVal() const
{
return val;
}
main.cpp
#include <iostream>
#include "example.h"
using namespace std;
int main()
{
example e;
cout << e.getVal() << endl;
}
I want to keep the getVal() method constant in my project, so I use that here.
Now, if I remove the inline keywords, I don't get errors. If I place the class dec and def in main.cpp, I don't get the errors. What is going on here?