Was not declared in this scope là gì năm 2024

  1. Lỗi was not declared in this scope.


  2. > bạn post toàn bộ code lên nhé. chắc bạn gọi hàm new_array trong hàm main, và bạn chưa khai báo function prototype[IMG]images/smilies/thinking.gif[/IMG]
  3. > a được rồi, mình copy function lên trên main là được rùi, thanks bạn nha [IMG]images/smilies/smile.png[/IMG]
  4. > ----Configuration: mingw5 - CUI Release, Builder Type: MinGW----
    Checking file dependency... Compiling C:\Users\MRPHUONG\Desktop\Untitled1.cpp... [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:25: error: `textcolor' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:26: error: `window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:32: error: `window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:42: error: `main' does not name a type [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:71: error: `x3' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:85: error: `C80' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:85: error: `textmode' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:95: error: `Window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:97: error: `textcolor' was not declared in this scope

Complete Make Untitled1: 9 error(s), 0 warning(s) ai jup e voi

-
  1. -
  2. >
    Was not declared in this scope là gì năm 2024
    Gửi bởi daongocphuong90
----Configuration: mingw5 - CUI Release, Builder Type: MinGW----

Checking file dependency... Compiling C:\Users\MRPHUONG\Desktop\Untitled1.cpp... [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:25: error: `textcolor' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:26: error: `window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:32: error: `window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:42: error: `main' does not name a type [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:71: error: `x3' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:85: error: `C80' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:85: error: `textmode' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:95: error: `Window' was not declared in this scope [Error] C:\Users\MRPHUONG\Desktop\Untitled1.cpp:97: error: `textcolor' was not declared in this scope

Complete Make Untitled1: 9 error(s), 0 warning(s) ai jup e voi

Bạn lập trình bằng Complier nào? Code này chắc chạy trên Borland C, có thư viện dos.h. Hình như các Complie mới sau này theo chuẩn c99, ko có thư viện dos.h ---

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  • BB code đang Bật
  • Smilies đang Bật
  • code đang Bật
  • code is Bật
  • HTML code đang Tắt

Nội quy - Quy định

Brian W. Kernighan, Dennis M. Ritchie, The C programming Language second edition, 1988, Chapter 2.1 Variable Names:

Don’t begin variable names with underscore, however, since library routines often use such names

Bjarne Stroustrup, Programming: Principles and Practice Using C++, 2014, Chapter 3.7 names:

If you read system code or machine-generated code, you might see names starting with underscores, such as _foo. Never write those yourself; such names are reserved for implementation and system entities. By avoiding leading underscores, you will never find your names clashing with some name that the implementation generated.

http://en.cppreference.com/w/cpp/keyword:

Also, all identifiers that contain a double underscore __ in any position and each identifier that begins with an underscore followed by an uppercase letter is always reserved and all identifiers that begin with an underscore are reserved for use as names in the global namespace.

Trong bài này mình sẽ giới thiệu một số lỗi biên dịch thường gặp khi biên dịch chương trình C/C++ bằng trình biên dịch GCC trên Linux/Unix và cách khắc phục.

1. undefined reference to ***

Đây là lỗi linker, xuất hiện khi linker không thể tìm thấy symbol đã được sử dụng. Thông thường nó hay xảy ra khi các hàm của một thư viện nào đó được sử dụng trong source code nhưng thư viện đó không được link.

Để thực hiện link một thư viện nào đó thì config như sau →

Với qmake

Với cmake

TARGET_LINK_LIBRARIES(target nameOfLib)

Lệnh g++

g++ -o main main.cpp -LdirOfLibrary -lnameOfLib

hoặc link trực tiếp bằng cách chỉ định file obiect như sau

g++ -o main main.o functionsModule.o

functionsModule.o là file object chứa code của function được sử dụng bởi main.o

2. error: *** was not declared in this scope

Lỗi này xảy ra khi một biến hoặc hàm không xác định nào đó được sử dụng.

— Trường hợp lỗi xảy ra với ‘biến’

Compiling error →

include

int main(int argc, char *argv[])

{

{

int i \= 2;

}

std::cout << i << std::endl; // i is not in the scope of the main function

return 0;

}

Fix →

include

int main(int argc, char *argv[])

{

{

int i \= 2;

std::cout << i << std::endl;

}

return 0;

}

— Trường hợp lỗi xảy ra với ‘hàm’

Thường xảy ra khi thiếu include header files (ví dụ sử dụng std::cout mà không có

include ) hoặc gọi hàm mà chưa có khai báo (hoặc định nghĩa) của hàm đó trước khi sử dụng, ví dụ :

Compiling error →

include

int main(int argc, char *argv[])

{

doCompile();

return 0;

}

void doCompile()

{

std::cout << "No!" << std::endl;

}

Fix →

include

void doCompile(); // forward declare the function

int main(int argc, char *argv[])

{

doCompile();

return 0;

}

void doCompile()

{

std::cout << "No!" << std::endl;

}

hoặc

include

void doCompile() // define the function before using it

{

std::cout << "No!" << std::endl;

}

int main(int argc, char *argv[])

{

doCompile();

return 0;

}

Note: Về cơ bản compiler biên dịch code từ trên xuống dưới. Tất cả mọi thứ đều phải được khai báo (hoặc định nghĩa) trước khi sử dụng.

3. fatal error: ***: No such file or directory

Compiler không tìm thấy file. Ví dụ trong 1 file source có

include “someFile.h” nhưng compiler không tìm thấy file “someFile.h” đâu cả. Trường hợp này chúng ta cần bổ sung thông tin config để compiler có thể tìm thấy file cần thiết.