LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ERROR: Class does not name a type (https://www.linuxquestions.org/questions/programming-9/error-class-does-not-name-a-type-942324/)

nontas.v 04-28-2012 04:24 PM

ERROR: Class does not name a type
 
Well, I've got a project in my university. It's about a supermarket simulation programm.

There's a lot of code, I'll put only the one that matters.
Code:

template<class T>
class ChainNode {
        friend Chain<T>;
        private:
                //prive data
};

template<class T>
class Chain {
        public:
                //public data
        private:
                //private data
};

After trying to compile I get the error: "Chain does not name a type"

I tried also to initialize the Chain class at first but no results.

I'm still kinda newbie in c++, so I would appreciate some plain explanation.
Thanks :)

millgates 04-28-2012 04:32 PM

Hello, can you also post the code which actually generates the error? How do you create an instance of Chain?

nontas.v 04-28-2012 04:42 PM

In my main I do the following (according to my book): Chain<int> L; //L shows how many instances will be created

that's what you mean? :/

millgates 04-28-2012 04:49 PM

Is the file that contains the definition of the template in the same file where you use it or included in the file? The template must be defined in each compilation unit where you use it.

nontas.v 04-28-2012 04:51 PM

well I changed the " friend Chain<T>; " with " friend class Chain; " and it worked...thanks for your time anyway :)

mitsosp 05-21-2012 10:16 AM

Eimai kai gw sto tmima s kai edw to idio provlima :/ .Ise sigouros oti ayto p ekanes doulevei? giati to vivlio to exei diaforetika.

nontas.v 05-22-2012 01:44 PM

sou stelnw pm :)

nontas.v 05-22-2012 01:45 PM

e-mail*


All times are GMT -5. The time now is 06:41 PM.