I already posted this question but not Minimal, Complete and Verifiable. So here it is again: Given are the following 5 very small files:
main.cpp
#include "bar.h"
#include <iostream>
int main()
{
const bar testBar;
testBar.barTest();
std::cin.get();
}
bar.h
#pragma once
#include "foobar.h"
class bar
{
public:
bar();
~bar();
void barTest() const;
private:
foobar* m_pFoobar;
};
bar.cpp
#include "bar.h"
bar::bar()
{
m_pFoobar = new foobar;
}
bar::~bar()
{
}
void bar::barTest() const
{
m_pFoobar->fooTest(*this);
}
foo.h
#pragma once
#include "bar.h"
class foo
{
public:
virtual void fooTest(const bar& b);
};
foobar.h
#pragma once
#include "bar.h"
#include "foo.h"
class foobar : public foo
{
public:
foobar();
~foobar();
void fooTest(const bar& b);
};
foobar.cpp
#include "foobar.h"
#include <iostream>
foobar::foobar()
{
}
foobar::~foobar()
{
}
void foobar::fooTest(const bar& b)
{
std::cout << "SUCCESS" << std::endl;
}
When I run this code, VS2015 is telling me the following:
Error C2664 'void foobar::fooTest(const int)': cannot convert argument 1 from 'const bar' to 'const int' bar.cpp 14
I don't understand the reason why the compiler interprets my function with an int
as argument. I hope someone can help me.