Initializing C++ string inside a constructor



Hello folks,

I want to initialize a variable type string s inside the class
constructor

My code looks like this

class Simple {

public:
Simple();
string s;
};

The problem I am encountering that I can not initialize s in an
initialization list, because my
value to initialize 's' is generated inside the constructor

Simple::Simple() {
// a string "somevalue" is generated here after some code
// can I do

s("somevalue");
or I will have to do
s= "somevalue";

Please help.

thanks

Nagrik

.



Relevant Pages

  • Re: Inherited Methods and such
    ... what I see in Initialize is ... Now, what you want is to get in the constructor of some S derived from T, ... The base types and registry are part of the framework and the user ... provides the concrete factories. ...
    (comp.lang.ada)
  • Re: TypeInitializationException when calling a static function from a timer
    ... and is trying to deference a null reference. ... Set a break-point in the static constructor and step through. ... that TypeInitializationException means is that some kind of failure ... wait until the last moment to initialize types). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Initialization & Inheritance
    ... for a recent project I was trying to initialize members of a derived ... class from the constructor of the super class (done using an abstract ... initialize, but double initialization. ... if you used the pointer as it stood, ...
    (comp.lang.java.programmer)
  • Re: Initializing static readonly methods
    ... public class TestClass ... //So assigning a value to readonly is perfectly fine. ... //readonly values are has to be initialized in constructor. ... There is no other place to initialize them. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: initialising properties in static constructor
    ... When static constructor is static it cannot initialize instance variables ... To intialize them in the constructor. ...
    (microsoft.public.dotnet.languages.csharp)