错误C2511 - 实例化 - func。在头文件中声明,但不在cpp文件中使用。 [英] error C2511 - instantiate - func. is declared in header file, but not used in cpp file.

查看:68
本文介绍了错误C2511 - 实例化 - func。在头文件中声明,但不在cpp文件中使用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在我的头文件中声明了一些函数,所有这些函数都可以工作,但我不明白为什么。



你可以在这里看到代码:



头文件:

Hi,
I declare some functions in my header file, all of them work but one, which i can't figure out why.

you can see the code here:

the header file:

class myfile
{
public:
	myfile(void);
	~myfile(void);
	int desplay();
	void print(int a[],int l);
/* here */	void print(int a[],int s,int l);
	void print(int a);
	void print(string s);
};





cpp文件:



the cpp file:

#include "stdafx.h"
#include "myfile.h"
#include <string.h>
#include <string>
#include <conio.h>
#include <iostream>
#include <fstream>
using namespace std;

#pragma region constructor_deconstructor
myfile::myfile(void)
{
}


myfile::~myfile(void)
{
}
#pragma endregion constructor_deconstructor

void myfile::print(int a[], int l){
	/* writes array a with l length to the end of a file (trace.txt) in the format:
	array:
	1 - 2 - 3 */
	ofstream fp;fp.open("trace.txt",ios::in | ios::app);
	if(fp.is_open()){
		fp.seekp(ios::ate,ios::end);
		fp<<endl;
	int i=0;
	print("\na[0..");print(l-1);print("] :\n");	
	for (i=0; i<l; i++){
		std::cout<<a[i];
		if(i<l-1)cout<<" - ";
		fp<<a[i];
		if(i<l-1)fp<<" - ";}
	}
}
/* here */
void myfile::print(int a[],int s, int l){
		/* writes array a with l length to the end of a file (trace.txt) in the format:
	array:
	1 - 2 - 3 */
	ofstream fp;fp.open("trace.txt",ios::in | ios::app);
	if(fp.is_open()){
		fp.seekp(ios::ate,ios::end);
		fp<<endl;
	int i=0;
	print("\na[0..");print(l-1);print("] :\n");	
	for (i=s; i<l; i++){
		std::cout<<a[i];
		if(i<l-1)cout<<" - ";
		fp<<a[i];
		if(i<l-1)fp<<" - ";}
	}
}

void myfile::print(int a){
	/* Prints a single number at the end of a file (trace.txt) */
	ofstream fp;fp.open("trace.txt",ios::in | ios::app);
	if(fp.is_open()){
		fp.seekp(ios::ate,ios::end);		
		std::cout<<a;
		fp<<a;}
}

void myfile::print(string s){
	/* Prints a string at the end of a file (trace.txt) */
	ofstream fp;fp.open("trace.txt",ios::in | ios::app);
	if(fp.is_open()){
		fp.seekp(ios::ate,ios::end);		
		std::cout<<s;
		fp<<s;}
}





你能告诉我它为什么会给我错误C2511关于这个函数说:

错误C2511:'void myfile :: print(int [],int,int)':在'myfile'中找不到重载的成员函数





can you tell me why it gives me the error C2511 about this function which says:
error C2511: 'void myfile::print(int [],int,int)' : overloaded member function not found in 'myfile'

with another error:
intelliSense: no instance of overloaded function "myfile::print" matches the specified type
And i have a redline under the 'print' where i've comented /* here */







为什么不是剩下的呢?

我应该怎么解决?



谢谢,




why not the rest of them?
and how should i fix it?

Thanks,

推荐答案

您发布的代码(通过简单的修改)编译得很好。我想你必须发布实际代码以获得更好的帮助。
The code you posted (with trivial modifications) compiles fine. I suppose you have to post the actual code to get better help.


我现在不用,



我刚删除我的解决方案中的文件'myfile.cpp'然后再次添加它并粘贴了错误所涉及的部分代码。然后它工作了!

它现在正在工作。
I Don't now,

I just removed the file 'myfile.cpp' from my solution then added it again and pasted the part of the code which the error was about. Then It Worked!
And it's working right now.


这篇关于错误C2511 - 实例化 - func。在头文件中声明,但不在cpp文件中使用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆