K
key9
Hi all
I think .h file offord a "catalog" of symbols and .cpp offord implements
but I have no idea why I got such an complier error
test.cpp: In function a€?int main(int, const char**)a€?:
test.cpp:14: error: no match for a€?operator<<a€? in
a€?operator<<(((VirtualScreen&)(& tmp_vs_)), i_a) << str_tmpa€?[0m
virtual_screen.h:17: note: candidates are: VirtualScreen&
operator<<(VirtualScreen&, int)
virtual_screen.h:15: error: expected initializer before a€?&a€? token
virtual_screen.h
===============================================================
#ifndef VIRTUAL_SCREEN_H
#define VIRTUAL_SCREEN_H
#include <string>
class VirtualScreen
{
public:
void printf_char(std::string ch);
}
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String);
//line 15
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number); //
line 17
#endif //VIRTUAL_SCREEN_H
virtual_screen.cpp
================================================================
#include <stdio.h>
#include <string>
#include "virtual_screen.h"
#include <sstream>
class VirtualScreen;
void
VirtualScreen::
printf_char(std::string ch)
{
fprintf(stdout,ch.c_str());
}
/* sample of over ride */
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String)
{
// Let the terminal print the string as it is.
std::stringstream Temp;
Temp << p_String;
p_vs.printf_char (Temp.str());
return p_vs;
}
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number)
{
// Convert the number to a string and let the terminal print the
// text representation of the number.
std::stringstream Temp;
Temp << p_Number;
p_vs.printf_char (Temp.str());
return p_vs;
}
======================================================================
test.cpp
#include <stdio.h>
#include <string>
#include "virtual_screen.h"
int main( int argc, const char* argv[] )
{
VirtualScreen tmp_vs_;
int i_a = 100;
std::string str_tmp = "This is test string";
tmp_vs_ << i_a << str_tmp;
return 0;
}
sorry for my last stupid post , I've just lost my mind.
thank you very
much
key9
I think .h file offord a "catalog" of symbols and .cpp offord implements
but I have no idea why I got such an complier error
virtual_screen.h:15: error: expected initializer before a€?&a€? tokeng++ -o test test.cpp virtual_screen.cpp
test.cpp: In function a€?int main(int, const char**)a€?:
test.cpp:14: error: no match for a€?operator<<a€? in
a€?operator<<(((VirtualScreen&)(& tmp_vs_)), i_a) << str_tmpa€?[0m
virtual_screen.h:17: note: candidates are: VirtualScreen&
operator<<(VirtualScreen&, int)
virtual_screen.h:15: error: expected initializer before a€?&a€? token
virtual_screen.h
===============================================================
#ifndef VIRTUAL_SCREEN_H
#define VIRTUAL_SCREEN_H
#include <string>
class VirtualScreen
{
public:
void printf_char(std::string ch);
}
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String);
//line 15
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number); //
line 17
#endif //VIRTUAL_SCREEN_H
virtual_screen.cpp
================================================================
#include <stdio.h>
#include <string>
#include "virtual_screen.h"
#include <sstream>
class VirtualScreen;
void
VirtualScreen::
printf_char(std::string ch)
{
fprintf(stdout,ch.c_str());
}
/* sample of over ride */
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String)
{
// Let the terminal print the string as it is.
std::stringstream Temp;
Temp << p_String;
p_vs.printf_char (Temp.str());
return p_vs;
}
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number)
{
// Convert the number to a string and let the terminal print the
// text representation of the number.
std::stringstream Temp;
Temp << p_Number;
p_vs.printf_char (Temp.str());
return p_vs;
}
======================================================================
test.cpp
#include <stdio.h>
#include <string>
#include "virtual_screen.h"
int main( int argc, const char* argv[] )
{
VirtualScreen tmp_vs_;
int i_a = 100;
std::string str_tmp = "This is test string";
tmp_vs_ << i_a << str_tmp;
return 0;
}
sorry for my last stupid post , I've just lost my mind.
thank you very
much
key9