Trouble with Strings

From: DJ (chopin3_at_earthlink.net)
Date: 10/25/04


Date: Mon, 25 Oct 2004 08:53:54 GMT

I am currently having trouble with strings. I have a private string variable
in my class and i assign a value to it in the creation function as follows.

#include <string>
using std::string;

#include <iostream>
using std::cout;
using std::endl;

class myclass{
private:
  string myString;
public:
  myclass();
  void testString();
};

myclass::myclass()
{
  myString = "Test";
  cout << "Inside " << myString << "!" << endl;
}

void myclass::testString()
{
  cout << "Outside " << myString << "!" << endl;
}

int main(){
  myclass m();
  m.testString();
  return 0;
}

Output looks like this.

Inside Test!
Outside !

Why am I losing the string outside of the scope of the initial function even
though it is a class member?

Thank you for any help,

David



Relevant Pages

  • Re: Trouble with Strings
    ... Ok I found my problem, too much java for my own good, you were all on the ... thus instantiating a second copy of myclass, ... I have a private string ... > in my class and i assign a value to it in the creation function as ...
    (comp.lang.cpp)
  • Re: dll export question / stl problem / C4251
    ... VS 2003 gives me lots of warnings on my STL ... string class members: ... void DoIt; ... dll-interface to be used by clients of class MyClass ...
    (microsoft.public.vc.stl)
  • Re: Instrumentation + BCEL | ASM
    ... final String owner, ... Strangely enough, with this method added, I can only transform methods with exactly one argument of type String). ... But I don't seem to know how to get hold of method signature, so there can be problems if consecutive threads call timed methods with the same name, but different signatures. ... private void genStartCode() { ...
    (comp.lang.java.programmer)
  • Yet another way to use Java
    ... * @param mainClass e.g. FontShower, ... StompProject (String mainClass, ... * does this project have a jar ... void mkDescBtm() ...
    (comp.lang.java.programmer)
  • Re: Creating multiple instances of objects
    ... > Can you post the server maincode, your IDL, and the full stack ... // Naming Service specification. ... typedef string tTbls; ... void SetCurrentTableraises; ...
    (comp.object.corba)