[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Forstaaelse problemmer i c++



> tirsdag 18 Marts 2008 skrev Allan W. Nielsen:
>> Hej
>>
>> Jeg er igang med at lave wet lille project i c++, og er l/obet ind i et
>> lille problem.
>>
>> F/olgende program illustrerer problemet:
>>
>> #include <string>
>> using namespace std;
>>
>> int main(){
>>   string s1;
>>   string s2();
>>
>>   s1 = "test af s1";
>>   s2 = "test af s2"; //compiler fejl her
>>   //her er fejlen
>>   //test.cpp: In function 'int main()':
>>   //test.cpp:11: error: assignment of function 'std::string s2()'
>>   //test.cpp:11: error: cannot convert 'const char [11]' to
>>   //             'std::string ()()' in assignment
>>
>>   return 0;
>> }
>>
>> Jeg trode at de 2 variable defineringer gjorde det samme,
>
> Mjaeh.
>
> "Mæ mindre je tar fejl" (sagt på sådan lidt jysk), så er string s2(); en
> erklæring af at der et eller andet sted i programmet findes en funktion
> der
> returnerer en string, som hedder s2.
>
> Prøv at skrive
>  cout << s2() << endl;
> og se hvad linkeren siger til dig.
>
> Akja, det er bare en af de 1000'vis af C++ gotchas, som man kan blive bidt
> af :-)
>
> Default constructoren er underforstået, hvis den ikke angives. Hvis du
> angiver
> den, så erklærer du en funktion.
>
> Der er nok endnu flere nuancer i det, i virkeligheden, men det er det der
> sker
> i dit program. Du kan så heller ikke assigne til den. Men, du kan definere
> funktionen et sted i den eller en anden fil :-)
>
> Mvh
>
> Mads
>
> --
> Mads Bondo Dydensborg.                               sslug@sslug
> Seattlement (n.): A self-serving agreement that preserves a monopoly,
> e.g.,
> by buying off a government.
>                                - Ganesh Prasad
>
> !DSPAM:47e01fdf252141804284693!
>
>

Hej igen

Det tog lidt tid at indse.... men jeg kan godt se at du har ret.

Fandt det ogsaa her
http://yosefk.com/c++fqa/ctors.html#fqa-10.2

Tak for hjaelpen
MVH
Allan W. Nielsen



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *