Hello!
I am studying C ++. The teacher on the monitor code in VS 2008 works, I have in VS 2010 does not work. Checked, everything is written correctly (ie, as a teacher).

The code itself (divided into 3 files):

//Определение класса Point #ifndef POINT_H #define POINT_H class Point { private: int x, y; public: int GetX() {return x;} //inline по умолчанию int GetY(); void SetX(int); void SetY(int); }; inline int Point::GetY() { return y; } #endif 

2 file:

 //Реализация класса Point #include"Point.h" void SetX(int _x) { x = _x >= 0 ? _x : 0; } void SetY(int _y) { y = _y >= 0 ? _y : 0; } 

3 file:

 //Использованиие класса Point (клиентский код) #include<iostream> #include"Point.h" using namespace std; int main() { Point a; a.SetX(10); a.SetY(20); cout << a.GetX() << ", " << a.GetY() << endl; system("pause"); } 

VS 2010 debugger error code:

 1>------ Построение начато: проект: Point, Конфигурация: Debug Win32 ------ 1>Построение начато 21.01.2012 21:14:51. 1>InitializeBuildStatus: 1> Обращение к "Debug\Point.unsuccessfulbuild". 1>ClCompile: 1> usePoint.cpp 1> Point.cpp 1>c:\users\vladislav\documents\visual studio 2010\projects\point\point.cpp(9): error C2065: x: необъявленный идентификатор 1>c:\users\vladislav\documents\visual studio 2010\projects\point\point.cpp(16): error C2065: y: необъявленный идентификатор 1> Создание кода... 1> 1>СБОЙ построения. 1> 1>Затраченное время: 00:00:00.55 ========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ========== 

What could be the cause? Project console (empty).

Grateful for the help. Thank.

  • The question is closed. Solution in the 1st answer. Thanks to all! - VladislavMSK

1 answer 1

In the "point.cpp" file instead

 void SetX(int _x) 

need to write

 void Point::SetX(int _x) 

Same with the game.

Such code should not be compiled. You missed something when rewriting.

  • Now another error: 1> c: \ users \ vladislav \ documents \ visual studio 2010 \ projects \ point \ point.cpp (7): error C2039: SetX: not a member of " global namespace'" 1>c:\users\vladislav\documents\visual studio 2010\projects\point\point.cpp(13): error C2039: SetY: не является членом " global namespace '" - VladislavMSK
  • Please tell me, what is it connected with? Why didn't it work for me, but did it work for the teacher? - VladislavMSK
  • one
    This code should not work for the teacher. You missed something. - andrybak
  • Perhaps, I'm just on Skype for someone else's webinar :). - VladislavMSK
  • one
    This code should not work for anyone ever. Something very strange. Ask this question to your teacher better. - skegg pm