[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] Konstante template argumenter i C++



On Fri, 21 Apr 2006 13:35:55 +0200, Mads Bondo Dydensborg wrote:

> 
> Ikke så vidt jeg kan vurdere. Jeg tror det er et løfte til brugeren om at 
> templaten ikke ændrer ved det referencen peger på... ?
> 
Prøvede lige et lille eksempel:
// name: template.cc
// compile: c++ -W -Wall -pedantic template.cc
#include <iostream>

template< class T >
class SayHi {

    public:
        SayHi() {}
        SayHi(const T &s) : name(s) {}
        void setName(const T &s) { name = s; }
        const T greeting() const { return name; }
        ~SayHi() {}

    private:
        std::string name;

};

int main() {
    SayHi< const std::string > sayHi;
    sayHi.setName("Adam");
    std::string name = sayHi.greeting();
    std::cout << name << std::endl;
    std::cout << "Adding family name to name and try inserting" << std::endl;
    name += " Ant";
    sayHi.setName(name);
    std::cout << sayHi.greeting() << std::endl;
    name += "s";
    char *s = const_cast< char *> (name.c_str());
    sayHi.setName(s);
    std::cout << "Greeting from a char*" << std::endl;
    std::cout << sayHi.greeting() << std::endl;
}

Som ovenstående viser, er den fuldstændig ligeglad med const eller ej
erklæringen. Mystiks:-\


-- 
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-05-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] *