Re: [Dev-C++] More Template Problems -- NewB
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abdelkader G. <go...@li...> - 2003-12-28 17:21:00
|
it's just a small problem with the type that you have declared:
> typedef jme::Index<const int, const std::string > T_index;
So, T_index now is considered as an alias to the type jme::Index<const int,
const std::string >
Consequently, accessing an attribute or a method that are not declared as
static for this class has no sense. Perhaps you intention was to declare a
variable which is an instance of T_index. In this case you should write
this:
<old code> T_index( i, name );
<correct code> T_index my_instance(i,name);
^^^^^^^^^^^
and change also this:
<old code> std::cout << T_index.getKey() << std::endl;
<correct code> std::cout << my_instance.getKey() << std::endl;
^^^^^^^^^^^
Kind regards,
> Can someone please lend me a hand with this, I get the concept of a
> template, but the dynamics are a bit complicated for me, can someone
> please tell me why I get an error saying:
> main.C: In function int main()
> main.C:15:error: parse error before '.' token
>
>
> Thanks
> ---------- index.C -----------
> #ifndef JME_INDEX_H
> #include "index.H"
> #endif
> ------------ index.H ------------
> #ifndef JME_INDEX_H
> #define JME_INDEX_H
>
> template<typename K, typename D>
> class Index{
> private:
> K Key;
> D Data;
>
> public:
> // C'tor
> Index(K const& kx, D const& dx): Key(kx), Data(dx){ }
> K const& getKey() const { return Key;}
> }; //Index
> } // jme
>
> #endif
>
> ---------- main.C -----------
> #include <string>
> #include <iostream>
> #include "index.H"
> int main(){
> const int i = 50;
> const std::string name( "Maya" );
> typedef jme::Index<const int, const std::string > T_index;
> T_index( i, name );
>
> ////<<--- This is the probme //////
> std::cout << T_index.getKey() << std::endl;
> ////<<--- This is the probme /////
>
>
> std::cout << "End of Index..." << std::endl;
> return 0;
> }
> --
>
> FYI
> http://www.astro.umd.edu/~marshall/abbrev.html
>
> E-Mail Policy
> http://www.vif.com/users/escalante/Email_Policy.html
>
> * You cannot exercise your power to a point of humiliation.
> - Jean Chretien
>
> * The media's the most powerful entity on earth. They have the
> power to make the innocent guilty and to make the guilty
> innocent, and that's power.
> - Malcom X
> * "Innocent until proven guilty", no... not in Canada!!
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for
> IBM's Free Linux Tutorials. Learn everything from the bash shell to
> sys admin. Click now!
> http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|