CLion saying a C++ class function doesn't exist when it does
CLion saying a C++ class function doesn't exist when it does
I have a class called Computer
and in it has a function called setPos
. Clion refuses to acknowledge the existence of getPos
or any other function I put in there except for the constructor.
Computer
setPos
getPos
snippet from main.cpp
Computer gateway = Computer::Computer("Gateway");
gateway.setPos(&neighbor,&supermarket, nullptr, nullptr);
Computer.hpp
class Computer
{
public:
Computer::Computer(string name);
void Computer::setPos(Computer* up, Computer* right, Computer* down, Computer * left);
string Computer::getName();
string name;
Computer* up = nullptr;
Computer* down = nullptr;
Computer* right = nullptr;
Computer* left = nullptr;
};
Computer.cpp
#include "Computer.hpp"
Computer::Computer(int level, bool hidden, string name, int money)
{
this->name = name;
}
void Computer::setPos(Computer* up, Computer* right, Computer* down, Computer * left)
{
this->up = up;
this->down = down;
this->right = right;
this->left = left;
}
string Computer::getName()
{
return this->name;
}
The function exists, my code works as intended, but CLion says it doesn't exist. How can I remedy this problem inside the IDE
Get rid of the
Computer::
in the header file you dont need to tell it what class it belongs to. It is obvious it is a part of Computer– JackVanier
6 mins ago
Computer::
Thank you @JackVanier that solved the issue!
– clbx
4 mins ago
1 Answer
1
As @JackVanier said, removing the class name from the declaration in the header file fixed the issue.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Your code doesn't look valid.
– chris
8 mins ago