Çözüldü C++ hata veriyor

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.
Katılım
27 Nisan 2022
Mesajlar
1.768
Çözümler
15
Aslında C++ ile pek uğraşmazdım ama lazım oldu. Birkaç pointer denemesi yapayım demiştim. Sonuç bu:
Hata:

Kod:
In file included from main.cpp:2:0:

dscriptcore.h:4:38: error: declaration of 'getinput' as array of functions.

 char getinput [] (char* inputtext)

 ^

dscriptcore.h:6:9: error: expected primary-expression before 'return'.

 return *inputtext;

 ^~~~~~

dscriptcore.h:6:9: error: expected '}' before 'return'.

dscriptcore.h:7:5: error: expected declaration before '}' token.

 }

Kodlar:
main.cpp:

C++:
#include <iostream>
#include "dscriptcore.h"
using namespace std;
int main ()
{
 char text [] = "abc";
 getinput(&text);
}

dscriptcore.h:

C++:
#include <iostream>
using namespace std;

 char getinput [] (char* inputtext)
 {
 return *inputtext;
 }
 
Çözüm
İşaretçi ve dizi mantığını kavrayamamışsın, tekrar gözden geçir.

C++:
#include <iostream>
#include "dscriptcore.h"

using namespace std;

int main() {

    char text [] = "abc";

    cout << getinput(text) << endl;

    return 0;
}

C++:
#ifndef DSCRIPTCORE_H
#define DSCRIPTCORE_H

char *getinput(char *inputtext) {

    return inputtext;
}

#endif
Aslında C++ ile pek uğraşmazdım ama lazım oldu. Birkaç pointer denemesi yapayım demiştim. Sonuç bu:
Hata:

Kod:
In file included from main.cpp:2:0:

dscriptcore.h:4:38: error: declaration of 'getinput' as array of functions.

 char getinput [] (char* inputtext)

 ^

dscriptcore.h:6:9: error: expected primary-expression before 'return'.

 return *inputtext;

 ^~~~~~

dscriptcore.h:6:9: error: expected '}' before 'return'.

dscriptcore.h:7:5: error: expected declaration before '}' token.

 }

Kodlar:
main.cpp:

C++:
#include <iostream>
#include "dscriptcore.h"
using namespace std;
int main ()
{
 char text [] = "abc";
 getinput(&text);
}

dscriptcore.h:

C++:
#include <iostream>
using namespace std;

 char getinput [] (char* inputtext)
 {
 return *inputtext;
 }

İnt main de return yapmamışsınız sanırım.
 
İşaretçi ve dizi mantığını kavrayamamışsın, tekrar gözden geçir.

C++:
#include <iostream>
#include "dscriptcore.h"

using namespace std;

int main() {

    char text [] = "abc";

    cout << getinput(text) << endl;

    return 0;
}

C++:
#ifndef DSCRIPTCORE_H
#define DSCRIPTCORE_H

char *getinput(char *inputtext) {

    return inputtext;
}

#endif
 
Çözüm
İşaretçi ve dizi mantığını kavrayamamışsın, tekrar gözden geçir.

C++:
#include <iostream>
#include "dscriptcore.h"

using namespace std;

int main() {

 char text [] = "abc";

 cout << getinput(text) << endl;

 return 0;
}

C++:
#ifndef DSCRIPTCORE_H.
#define DSCRIPTCORE_H.

char *getinput(char *inputtext) {

 return inputtext;
}

#endif

Allah razı olsun. Ama nedeni nedir? Gerçekten bazen aklım Python'a gidiyor. Benimki ile farkı nedir kodun? Anlatırsanız.
 
Son düzenleyen: Moderatör:

Yeni konular

Geri
Yukarı