这是我的 .h 文件的一些错误,当我在其中包含我的类模板时显示 [Error] 未终止 #ifndef

Uts*_*sav -5 c++ inheritance templates constructor class

头文件

#ifndef WIKI_H
#define WIKI_H

template<class T>

class Rectangle
{

    private:

        T length;
        T breadth;

        void printarea();

        public:

            Rectangle();
};
Run Code Online (Sandbox Code Playgroud)

源文件

#include "Wiki.h"
#include <iostream>

using namespace std;

void Rectangle::printarea()
{

    cout<< "Area = " << length*breadth <<endl; 
}

Rectangle::Rectangle()
{

    cout<< "Enter Length" <<endl;
    cin>> lenght;
    cout<< "Enter Breadth" <<endl;
    cin>> breadth;

    printarea();
} 
Run Code Online (Sandbox Code Playgroud)

主文件

#include <iostream>
#include "Wiki.h"

using namespace std;

int main()
{

    Rectangle<int>X;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Lia*_*ter 6

您需要将 a 添加#endif到头文件的末尾。

  • @Utsav /sf/ask/34651501/ (2认同)