'Anonymous struct' Compile error in custom library


hi all,

i'm trying write first library struggling compile properly. it's relatively simple class that's supposed store list of known wifi networks along passwords , connect strongest one. note it's near finished, wanted test had far, ran problems... here's contents of .h file:

code: [select]
#ifndef bcn_wifi
#define bcn_wifi

#include "arduino.h"
#include <esp8266wifi.h>

class bcn_wifi {
public:
        //bcn_wifi;
void addnetwork(char* sssid, char* spwd);
bool setup_wifi();
void list_networks();

private:
static wificlient espclient;
char* myssids[5];
char* mypwds[5];
int iused;
int32_t myrssi[5];
};
#endif


and here's corresponding .cpp file:

code: [select]
/*
this file manage wifi connections on esp8266
*/

#include <esp8266wifi.h>
#include "bcn_wifi.h"
#include "arduino.h"

/*
// default constructor
bcn_wifi::bcn_wifi() {
//do nothing
}
*/

void bcn_wifi::addnetwork(char* sssid, char* spwd) {

if (iused < 5){
myssids[iused] = sssid;
mypwds[iused] = spwd;
iused += 1;
}
}

void bcn_wifi::list_networks() {
//list stored networks - debugging
for (int j = 0; j < iused; ++j){
serial.println(myssids(j));
serial.println(mypwds(j));
serial.println("");
}
}

bool bcn_wifi::setup_wifi() {

//scan networks
// set wifi station mode , disconnect ap if connected
wifi.mode(wifi_sta);
wifi.disconnect();
delay(100);

int n = wifi.scannetworks();

if (n == 0)
//wait second before trying again
delay(1000);
else {
for (int = 0; < n; ++i){
for (int j = 0; j < iused; ++j){
if (strcmp(wifi.ssid(i), myssids(j)) == 0) {
myrssi(j) = wifi.rssi(i);
}
}
}



}
}


here's code i'm using in arduino ide test:

code: [select]
#include "bcn_wifi.h"

bcn_wifi mywifi;

void setup() {
  // put setup code here, run once:

}

void loop() {
  // put main code here, run repeatedly:

}


when hit compile following errors:

c:\users\me\documents\arduino\libraries\bcn_wifi/bcn_wifi.h:7:16: error: anonymous struct cannot have function members

 class bcn_wifi {

                ^

c:\users\me\documents\arduino\libraries\bcn_wifi/bcn_wifi.h:20:1: error: abstract declarator '<anonymous class>' used declaration

 };

 ^

sketch_aug23a:3: error: 'mywifi' not name type

 bcn_wifi mywifi;

          ^

exit status 1
'mywifi' not name type


i'm stuck on compiler means 'anonymous' both in terms of struct , class. if i'm honest, have no idea means 'mywifi' not name type either... if possible, tell me i'm doing wrong point me in direction of literature me understand i've done wrong? i've tried dr. google he's not been of use.

thanks in advance,

ben.

the problem include guard. you've #define'ed bcn_wifi nothing. imagine pre processor going through code , deleting every occurrence of "bcn_wifi".

if include guard looked you'd fine.

code: [select]

#ifndef bcn_wifi_h
#define bcn_wifi_h






Arduino Forum > Using Arduino > Programming Questions > 'Anonymous struct' Compile error in custom library


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'