कोड:एक कॉन्स्ट और इनलाइन सदस्य फ़ंक्शन घोषित और कार्यान्वित कैसे करें?
point3f.h
Class Point3f {
...
inline void project2D(ProjType p, const Point2i& view) const;
};
point3f.cpp
inline void Point3f::project2D(ProjType p, const Point2i& view) const {
switch(p) {
case PROJ_XY:
glVertex2f(x * view.x, y * view.y);
break;
case PROJ_YZ:
glVertex2f(y * view.x, z * view.y);
break;
case PROJ_XZ:
glVertex2f(x * view.x, z * view.y);
break;
default:
break;
}
}
इस कार्यप्रणाली को कॉल संकलन समय में किसी त्रुटि को जन्म देती है:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'
मैं बिना हर मामले की कोशिश की और inline
प्रतीक के साथ:
inline
शीर्षक में, सीपीपी में नहीं:
Warning: inline function ‘void Point3f::project2D(ProjType, const Point2i&) const’ used but never defined [enabled by default
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
शीर्षक में inline
, यह भी सीपीपी में:
Warning: inline function ‘void Point3f::project2D(ProjType, const Point2i&) const’ used but never defined [enabled by default
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
नहीं शीर्षक में है, लेकिन सीपीपी में:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
शीर्षलेख में नहीं, न तो सीपीपी में:
It works but that's not what I want
प्रश्न:
- करता
const and inline member function
मेकअप भावना? const and inline member function
घोषित कैसे करें?
अग्रिम धन्यवाद।
स्पष्टीकरण के लिए, समस्या 'const' और' inline' (मैं इसे हर समय करता हूं) के मिश्रण में नहीं है, लेकिन इस तथ्य में कि 'इनलाइन' हेडर फ़ाइल में होना चाहिए। –
आपने जो कहा है उसके बाद, जी ++ सिर्फ एक और चेतावनी उठाता है कि 'चेतावनी: इनलाइन फ़ंक्शन' शून्य पॉइंट 3 एफ :: प्रोजेक्ट 2 डी (प्रोजेटाइप, कॉन्स प्वाइंट 2i और) कॉन्स्ट 'का उपयोग किया जाता है लेकिन कभी परिभाषित नहीं किया गया है [डिफ़ॉल्ट रूप से सक्षम] ' –
@ComboZhc नहीं डालें बिल्कुल .cpp फ़ाइल में फ़ंक्शन। हेडर में * केवल * रखो। –