Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    lỗi chẳng liên quan gì tới template.

    error C2958: the left parenthesis '(' found at 'c:\users\win7\desktop\con đường lập trình\3_7_2014\3_7_2014\array1d_t_p_cpp.h(12)' was not matched correctly
    // chỉnh đường dẫn lại thành relative path, hoặc là bỏ kí tự unicode và khoảng trắng đi

    error C3861: 'arrInput': identifier not found
    // lỗi cú pháp, biến chưa được khai báo

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Vấn đề sử dụng template và định nghĩa toán tử phân số trong C++ dùng Visual studio 2012!!!

    //Đây là tập tin .h
    #ifndef _ARRAY1D_T_H
    #define _ARRAY1D_T_H

    #include <malloc.h>
    #include <iostream>
    using namespace std;

    template <class T>
    void arrPushBack(T *&a, int &n, T x)
    {
    int m = n + 1;
    T *anew = (T*)realloc(a, m*sizeof(T);
    if(anew != NULL)
    {
    anew[n] = x;
    a = anew;
    n++;
    }
    }

    template <class T>
    void arrInput(T* &a, int &n)
    {
    T x;
    a = NULL; n = 0;
    while(cin >> x)
    {
    arrPushBack(a, n, x);
    }
    }

    template <class T>
    void arrOut(T a[], int n)
    {
    for(int i = 0; i < n; i++)
    {
    cout << a[i] << " ";
    }
    }
    #endif




    //Đây là chương trình chính
    #include "Array1D_T_P_CPP.h"
    #include <iostream>
    using namespace std;
    struct phanSo{
    int tuso, mauso;
    };

    ostream& operator <<(ostream& outDev, const phanSo& ps)
    {
    if(ps.mauso== 1 || ps.tuso == 0)
    outDev << ps.tuso;
    else
    outDev<< ps.tuso <<"/"<< ps.mauso;
    return outDev;
    }
    istream& operator >>(istream& inDev, phanSo &ps){
    inDev >> ps.tuso >> ps.mauso;
    return inDev;
    }
    void main()
    {
    phanSo *B; int nB;
    cout << "Input elements of array:
    ";
    arrInput(B, nB);
    //Do something here...
    cout << nB << "element(s):
    ";
    arrOut(B, nB);
    //Free allocated memory
    if(B != NULL)
    free(B);
    }

    //Khi chạy chương trình thì luôn thông báo 2 lỗi :
    error C2958: the left parenthesis '(' found at 'c:\users\win7\desktop\con đường lập trình\3_7_2014\3_7_2014\array1d_t_p_cpp.h(12)' was not matched correctly
    error C3861: 'arrInput': identifier not found

    Có cao thủ nào từng trải chỉ dạy em với ạ!!! Mới chuyển qua C++ nên chưa rành lắm sử dụng cái template này [IMG]images/smilies/2.gif[/IMG]

 

 

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
  •