我对C++有点新鲜,并且在自己的项目中一直在努力。我遇到了一个错误与此头和.cpp文件标题中带有“std :: cout”的非静态成员引用
// main.cpp
#include <iostream>
#include "Header.h"
int main() {
MyClass::TestFunction(); //'MyClass::TestFunction': illegal call of non-static member function
}
// header.h
#ifndef HEADER_H
#define HEADER_H
#include <iostream>
class MyClass {
public:
void TestFunction() {
std::cout << "Hello World\n"; //Where I beleive the issue is
}
};
#endif
现在我认为问题来自std::cout
不是静态的,main.cpp
需要申报它是静态的,但我不知道如何使其成为静态,以便main.cpp
正常工作。如果任何人都可以给我一个提示,我怎么能做出这样的事情以后工作前进的道路,这将是真棒:)
的[权威的C++书指南和列表]可能的复制(http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – LogicStuff
问题是, 'TestFunction'不是静态的,但是你使用调用静态函数的语法调用它。 –