I'm sure there have been many similar questions asked, but since I'm not very familiar with C++, I don't exactly know what to look for/what to call it.
I've got a class which is trying to use a void method to print out an std::string
it has a a public variable. When I try, I get a lengthy error report of the following reported several times:
c:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(785): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
header
#include "stdafx.h"
#include "iostream"
class Person
{
public:
Person(void);
Person(std::string);
int myInt;
std::string myString;
~Person(void);
void SayHi();
void MyName();
};
--
cpp
#include "stdafx.h"
#include "iostream"
#include "Person.h"
Person::Person(void)
{
myInt = 23;
}
Person::Person(std::string s)
{
myString = s;
}
Person::~Person(void)
{
}
void Person::SayHi()
{
std::cout<< "say hi" <<std::endl;
}
void Person::MyName()
{
std::cout<< this->myString; //if this line is commented out, program runs fine
std::cout<< "I can print to the console" <<std::endl;
}
-- main
#include "stdafx.h"
#include "Person.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
int main()
{
Person p;
Person p2 = Person("Darrin");
p2.SayHi();
p2.MyName();
}
I can print out the pointer this
in the MyName method and intellisense pops up myString in the MyName method, why does it blow up when I compile it?