way of defining class in a namespace

前端 未结 6 763
悲哀的现实
悲哀的现实 2020-12-11 08:11

I defined a class in a namespace in a header as follows

#ifndef _c1_
#define _c1_

namespace classspace
{
    class Aclass;
}

class Aclass
{
    //body
};

         


        
6条回答
  •  情深已故
    2020-12-11 08:55

    You declare the class within the namespace but define it outside the namespace. So the declaration is:

    classspace::Aclass
    

    but the definition defines the implementation for:

    ::Aclass
    

    Namespaces should match for declaration and definition.

提交回复
热议问题