English 中文(简体)
1. 类型错误的参考资料的无效初始化
原标题:Invalid initialization of reference of type error

百万人感谢愿意帮助我的人。

第一,该法:

#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

void Beolvas (vector<vector<int> > mat);
bool VanNemNull (const vector<vector<int> > &mat);

int main()
{
cout << "Van-e a mátrixnak olyan oszlopa, hogy a főátló alatt csak 0-át tartalmaz, és ha igen, akkor melyik az?
" <<endl;

    char ch;
    do{
        // Adatbevitel
        vector<vector<int> > mat;
        Beolvas(mat);

        //Kiértékelés
        int i;
       if (VanNemNull(&mat[i])) cout<<"szupiiiiii";

        cout<< endl << "Futtassam újra?   (I/N)";cin>>ch;
        }while (ch!= n  && ch!= N );
    return 0;
}

void Beolvas(vector<vector<int> > mat)
{
    ifstream fajl;
    bool hiba;
    string str;

    do{
        cout << "Fajl neve:";
        cin >> str;
        fajl.open(str.c_str());
        if (hiba = fajl.fail())
        {
            cout << "Nincs ilyen nevű fájl" << endl;
            fajl.clear();
        }
    }while (hiba);

    int n;
    fajl >> n;
    if (n<1)
    {
        cout<<"Helytelen a mátrix mérete
 Kérem ellenőrizze a forrásfájlt!
";
        cout<<"E megnyomásával kilép"<<endl;

    char ex;
    do{
        cin>>ex;
        }while (ex!= e  && ex!= E );exit(0);
    }

    mat.resize(n);
    for(int i=0; i<n; ++i)
        {
            mat[i].resize(n);
            for (int j=0; j<n; ++j)
            {
                fajl >> mat[i][j];
            }
        }
    fajl.close();
    cout<<"A mátrix a következöképpen néz ki:"<<"
";
    cout<<"Elemszáma: "; cout<<n*n<<"
";
    for (int i=0; i<n; ++i)
        {
            for (int j=0; j<n; ++j)
            {
                cout<<mat[i][j]<<"	";
            }
            cout<<"
";

        }

}

/*void Vansor (const vector<vector<int> > mat)
{
    //bool l = false;
}*/

bool VanNemNull (const vector<vector<int> > mat)
{
    bool l = false;
    int i=0;
    cout<<(int)mat.size();
    for (int j=i+1; !l && j<(int)mat.size(); ++j)
    {
        cout<<mat[j][i]<<"
";
        if (l) cout<<"hej
";
        l = (mat[j][i]!=0);
        if (l= true) cout<<"22"; else cout<<"11";

    }
    return (l);
}

主要问题是最后一部分。 此外,我收到这些错误信息:

||In function `int main() :|
|23|error: invalid initialization of reference of type  const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&  from expression of type  std::vector<int, std::allocator<int> >* |
|9|error: in passing argument 1 of `bool VanNemNull(const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&) |
||=== Build finished: 2 errors, 0 warnings ===|
最佳回答

第一位编辑:

vector<vector<int> > mat;
...
if (VanNemNull(&mat[i])) cout<<"szupiiiiii";

与之不相匹配:bool VanNemNull (const path<vector<int> > mat);

you are passing a copy of a vector_of_ints (an element of vector_of_vector_of_int) as parameter. You should either call it like this :

if (VanNemNull(mat)) ...

或者改变这样的功能:

 bool VanNemNull (const vector<int> > mat);

并改变tation(关于使用mat[j][i])。

您还使用<代码>if中的变量一(VanNemNull(&mat[i]) 即刻版。

Second ,your call to

void Beolvas(vector<vector<int> > mat );

is also done with a copy of mat ,so the changes you make in BeolVas(..) are applied to that copy and will be lost when the function returns. you should change it to :

void Beolvas(vector<vector<int> >& mat )

问题回答

<代码>&mat[i]有以下类型:vector<int>*,并将之转至参考vector<vector<int>>。 我不理解你的法典在做些什么,足以告诉你如何确定它,但现在你知道错误意味着什么。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签