Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
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);
};


the cpp file:
C++
#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;}
}


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'

SQL
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,
Posted
Updated 5-Aug-14 0:09am
v4
Comments
m.r.m.40 5-Aug-14 7:22am    
Seems like i cannot define a function like:
void myfile::print(int a[], int l,int s)
I cannot figure it out.
[no name] 5-Aug-14 7:39am    
Since you code compiles just fine on my system and Carlo's system, maybe you should be looking at your version of VS.
m.r.m.40 5-Aug-14 10:09am    
:DIt's interesting i'll check on another system.
m.r.m.40 5-Aug-14 10:25am    
It's working right now.
well i'm using VS 11.0.5
Please reed my reply's to Carlo.
Philippe Mori 5-Aug-14 22:04pm    
IntelliSense errors are not always errors. Try to build solution and see if the error still occurs. Also restarting Visual Studio sometime help or rebuilding the solution.

IntelliSense might sometime get desynchronized or other errors in the solution might cause suspicious messages.

The code you posted (with trivial modifications) compiles fine. I suppose you have to post the actual code to get better help.
 
Share this answer
 
Comments
m.r.m.40 5-Aug-14 5:41am    
I'll just update it
m.r.m.40 5-Aug-14 5:44am    
Now it's updated to the full cpp file
CPallini 5-Aug-14 5:53am    
Moving the
#include "myfile.h"
after the
using namespace std;
one (and minor changes) made it compile fine, on my system.
m.r.m.40 5-Aug-14 10:23am    
I don't understand what's going on.
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.
Can you tell me why?
m.r.m.40 5-Aug-14 10:28am    
Was that a bug?
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900