5

Không thể nhận được bất kỳ mã sử dụng bảo vệ phần đầu để biên dịch trong vs 2010. Ví dụ:C++ bảo vệ tiêu đề sẽ không biên dịch

#ifndef SIMPLE.H 
#define SIMPLE.H 

#include <iostream> 

class Place { 
private: 
int m_xplace; 
int m_yplace; 
Place(){} 
public: 
Place(int x, int y) : m_xplace(x), m_yplace(y) {} 
void Move(int x, int y); 
void set_place(int x, int y) {m_xplace = x, m_yplace = y;} 
int get_place_x() {return m_xplace;} 
int get_place_y() {return m_yplace;} 
}; 
#endif 

tôi nhận ra điều này từ trình biên dịch:

1>------ Build started: Project: 1, Configuration: Release Win32 ------ 
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor  directive - expected a newline 
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition 
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor directive - expected a newline 
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition 
========== 
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Am tôi thiếu một cái gì đó hiển nhiên ở đây? Tôi khá chắc chắn rằng tôi có cú pháp chính xác. Cảm ơn.

Trả lời

16

Bạn không thể sử dụng . trong số nhận dạng.

Hãy thử điều này thay vì:

#ifndef SIMPLE_H 
#define SIMPLE_H 
+0

Ahhhhhhhh. Lol. –

+3

Bây giờ tôi nhìn lại nó, đầu ra là khá rõ ràng như những gì là sai. –

+0

Vâng, điều đó xảy ra. Tôi cũng bỏ qua mọi thứ, và bắt đầu tìm kiếm lỗi ở những nơi sai (giống như chính mã). – Mysticial

Các vấn đề liên quan