error C2065: ' ' : undeclared identifier
场景:error C2065: undeclared identifier解决方案
error C2065: undeclared identifier
初学C++,麻烦各位大神帮帮忙,很简单的程序:
基类:
调试的时候出现如下错误:
--------------------Configuration: 7 - Win32 Debug--------------------
Compiling...
7.cpp
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2065: 'Derived' : undeclared identifier
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2146: syntax error : missing ';' before identifier 'd'
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2065: 'd' : undeclared identifier
C:\Documents and Settings\user\桌面\C++\7.cpp(7) : error C2228: left of '.size' must have class/struct/union type
执行 cl.exe 时出错.
7.obj - 1 error(s), 0 warning(s)
麻烦问一下错在哪,该怎么改呢,谢谢
------解决方案--------------------
扩展类:
#ifdef DERIVED_H
#define DERIVED_H
这里要改成
#ifndef DERIVED_H
#define DERIVED_H
error C2065: undeclared identifier
初学C++,麻烦各位大神帮帮忙,很简单的程序:
基类:
- C/C++ code
#ifndef BASE_H #define BASE_H class Base { public: size_t size() const { return n; } Base(size_t n1 = 0) : n(n1){} protected: size_t n; }; #endif 扩展类: #ifdef DERIVED_H #define DERIVED_H #include "Base.h" class Derived : private Base { public: using Base::size; Derived(size_t n1 = 0):Base(n1),n(n1){} protected: using Base::n; }; #endif 测试类: #include <iostream> #include "Derived.h" using namespace std; int main(){ int i = 3; Derived d(i); cout << d.size() << endl; return 0; }
调试的时候出现如下错误:
--------------------Configuration: 7 - Win32 Debug--------------------
Compiling...
7.cpp
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2065: 'Derived' : undeclared identifier
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2146: syntax error : missing ';' before identifier 'd'
C:\Documents and Settings\user\桌面\C++\7.cpp(6) : error C2065: 'd' : undeclared identifier
C:\Documents and Settings\user\桌面\C++\7.cpp(7) : error C2228: left of '.size' must have class/struct/union type
执行 cl.exe 时出错.
7.obj - 1 error(s), 0 warning(s)
麻烦问一下错在哪,该怎么改呢,谢谢
------解决方案--------------------
扩展类:
#ifdef DERIVED_H
#define DERIVED_H
这里要改成
#ifndef DERIVED_H
#define DERIVED_H